0

我正在尝试从一个单元读取串行数据并通过 RX/TX 引脚将其打印到非 PC 控制器中。这是我编写的代码,但它似乎不起作用。有没有人有什么建议?

void keypad(const char *event, const char *data);//forward declaration
String outgoingString;
void setup() {
Serial1.begin(9600, SERIAL_8N2);//begin serial at: 9600baud, 8 data bits, no 
parity, 2 stop bits
Particle.subscribe("Janus485b", keypad, MY_DEVICES);// subscribe to 
secondary publish of data from keypad
}

void loop() {
//read incoming data on serial, and publish back to secondary for keypad
while(Serial1.available() > 0){
String incomingString = Serial1.readStringUntil('\n');
Particle.publish("Janus485a", incomingString, PRIVATE);
Serial1.flush();//wait for serial buffer to empty
}

}
void keypad(const char *event, const char *data) {
//read incoming data from secondary at keypad, write to controller
String outgoingString = ("received value=0x%x", outgoingString);
Serial1.write((uint8_t*)&data, sizeof(data));
Serial1.flush();//wait for serial buffer to empty
}
4

0 回答 0