从发送器接收数据时遇到一些麻烦。我的应用程序具有表单界面。我的发送器读取串行数据,将字符串收集到char数组中,然后发送。串行数据由一个周期值(n毫秒),一个区分字符(例如“-”)和脉冲宽度百分比(例如Serial.readString()= 6000-45)组成。但是,在我阅读时,它每字节发送数据。同样,接收器每字节接收数据。发送和接收字节很容易,但是我对如何正确接收char数组感到困惑。 感谢您的进一步支持。
//transmitter part
char* msg;
String mystring;
int len;
void setup(){
//transmitter pin etc.
}
void loop(){
if(Serial.available()>0){
mystring = Serial.readString();
len = mystring.length()+1;
msg = (char*)malloc(len);
mystring.toCharArray(msg,len);
vw_send(((uint8_t*)msg),strlen(msg));
vw_wait_tx();
delay(100);
}
}
//receiver part is empty since I couldn't figure out the logic of it
//As I read at Arduino forum, vw_get_message() gets only one character