我想回显Linux发送给Arduino的数据,这是一个十六进制命令,因为我需要PHP读取的回显数据。问题是我不想使用换行符来打印完整的数据。当Arduino没有更多的数据可读取时,我想打印它。下面是代码:
我想要做的是:
\n,如何识别读取序列的结尾Arduino代码:
char printByte[100];
byte getByte;
int pos = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
if(Serial.available() > 0){
getByte = Serial.read();
printByte[pos] = getByte;
pos++;
printByte[pos] = '\0';
if(getByte == '\n'){
Serial.print(printByte);
for(int i=0; i<=sizeof(printByte);i++){
printByte[i]=0;
}
pos = 0;
}
}
}Linux示例代码在发送十六进制..。
unsigned char pCom[2][7]={{0xFF,0x01,0x00,0x10,0x2F,0x2F,0x6F},
{0xFF,0x01,0x00,0x08,0x2F,0x2F,0x67}};
write(fd,pCom[0],8);另外,我如何减少Arduino代码,比如0x,这样它只会输出FF 01 10等等?
发布于 2012-08-22 20:20:51
来自Arduino参考页面( http://arduino.cc/en/Serial/Print ):
Serial.print(78, HEX) gives "4E" 所以:
Serial.print(printbyte, HEX);应该给你你想要的输出。
https://stackoverflow.com/questions/12076240
复制相似问题