从云端读取序列并写入非PC控制器

时间:2018-03-23 13:45:26

标签: c++ particle-photon

我正在尝试从一个单元读取串行数据并通过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
}

0 个答案:

没有答案