问题比较解析的串行数据

时间:2014-12-16 02:48:22

标签: c++ arduino-uno

我遇到问题让我的功能继续执行if(Status ==" True")声明,但我不确定原因。当我打印他们似乎匹配的线条。我还包括了一个串行输出的样本。

B' RCSSTATUS \ r \ n' B'假\ r \ n' B' RCSSTATUS \ r \ n' B'假\ r \ n' B' RCSSTATUS \ r \ n' B'假\ r \ n'

com = command = DATASET =' RCSSTATUS' +结果+' \ n' =真

void parseCommand(String com){

String Action;
String Status;
Action = com.substring(0, com.indexOf(" "));
Status = com.substring(9, com.indexOf("e") + 1);
    Serial.println(Action);
if(Action == "RCSSTATUS")
{Serial.println(Status);
    if(Status == "True"){
        digitalWrite(5, HIGH);
        digitalWrite(4, LOW);
}
        if(Status == "False"){
                            digitalWrite(6, HIGH);
            digitalWrite(4, HIGH);
            digitalWrite(5, LOW);
}}}

1 个答案:

答案 0 :(得分:0)

我明白了。我的输出字符串在行的开头有一个空格。将if(Status == "True")更改为if(Status == " True")