Arduino串行TX和RX消息
我正在使用Arduino和M5邮票( https://shop.m5stack.com/products/ M5STAMP-PICO-5PCS ),并尝试实现TX和RX消息的串行接口。 TX消息类似于0x55 0xcd 0x47 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0x69 0x69 0x0d 0x0a
和Rx Messages类似x00 0x03 0x00 0x00 0x00 0x2a 0x00 0x0c 0x00 0x00 0x04 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x47 0x47 0x03 0xe3 0xe3 0x0d 0x0d 0x0a and Code> eys 40 hex。
我设法提出了一个令人讨厌的解决方案,其中包括40个十六进制,并打印出消息。
void receivemsgloop(void *pvParam)
{
Serial.println("receivemsgloop start");
int incomingByte = 0;
unsigned char msg[40];
int i = 0;
while (1)
{
if (Serial2.available() > 0)
{
// read the incoming byte:
incomingByte = Serial2.read();
// counting the incomingByte and store in the array??
if (i < 40)
{
msg[i] = incomingByte;
i++;
}
else
{ //else array full and print out
Serial.print("s2 received msg: ");
for(int c=0;c<40;c++){
Serial.println(msg[c],HEX);}
Serial.println();
i=0;
}
}
}
Serial.println("receivemsgloop end");
}
无论如何,是否在不使用阵列循环的情况下存储了十六进制阵列?我已经尝试了serial.ReadSting(),但实际上无法正常工作。谢谢。
I am using Arduino with M5 Stamp (https://shop.m5stack.com/products/m5stamp-pico-5pcs) and trying to implement a serial interface to tx and rx message . The Tx message is like 0x55 0xCD 0x47 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0x69 0x0D 0x0A
and the Rx message is like 0xAA 0x00 0x00 0x00 0x00 0x02 0xDA 0x00 0x00 0x03 0x32 0x08 0x8E 0x18 0xF6 0x00 0x03 0x00 0x00 0x00 0x2A 0x00 0x0C 0x00 0x04 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x47 0x03 0xE3 0x0D 0x0A
and always is 40 HEX.
I manage to come up with a nasty solution of counting 40 HEX with array and print the message out.
void receivemsgloop(void *pvParam)
{
Serial.println("receivemsgloop start");
int incomingByte = 0;
unsigned char msg[40];
int i = 0;
while (1)
{
if (Serial2.available() > 0)
{
// read the incoming byte:
incomingByte = Serial2.read();
// counting the incomingByte and store in the array??
if (i < 40)
{
msg[i] = incomingByte;
i++;
}
else
{ //else array full and print out
Serial.print("s2 received msg: ");
for(int c=0;c<40;c++){
Serial.println(msg[c],HEX);}
Serial.println();
i=0;
}
}
}
Serial.println("receivemsgloop end");
}
Is there have anyway store the HEX array without using the array loop? I have try the Serial.readSting() but not really working. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新了该功能,并添加了一个IF为检查结束序列的原因,如果结束序列不丢弃0x0d 0x0a。测试了一个晚上,看起来还可以。
updated the function and added a if cause for checking the ending sequence if the ending sequence is not0x0D 0x0A discard it. Tested for one night and seem ok.