- # include <stdlib.h>
- # include <string.h>
- String cdjo = "B07000C0";
- String comdata = "";
- unsigned char itea[6] = {0xB0,0x70,0x30,0x1C,0x77,0xEC};
- void setup() {
-
- Serial.begin(9600,SERIAL_8E1);
- while(Serial.read() >= 0){}//清除串口缓冲区
- }
- String readLine()//读整行字符串子程序
- {
- String comdata="";
- while(Serial.available())
- {
- comdata += char(Serial.read());
- delay(2);
- }
- return comdata;
- }
- void loop()
- {
- comdata=readLine();//读整行字符串
- //Serial.print(comdata);//调试用,执行到这里都正常
- if(comdata=="B07000C0")//这个语句始终无法正确判断
- {
- Serial.print(comdata);//调试用
- //Serial.write(itea,6);
- comdata = "";
- while(Serial.read() >= 0){}//清除串口缓冲区
- delay(200);
- }
- }
复制代码 |