开始在处理和字符串工作不比较

时间:2014-02-09 22:00:23

标签: java processing

我有以下代码:

String myString = port.readStringUntil(linefeed);

  if (myString != null) {
    print(myString);
    if (myString.equals("SndEprom")) {
      sending = true;
      print("sending set true");
    }

当代码运行时,这就是日志显示的内容:

SndEprom
0,255
1,255
2,255
3,255
4,255
5,255
6,255
....

我会想到这一行

  

print(“发送设置为true”);

会跑。我做错了什么?

谢谢,

洛伦

发送eeprom数据的arduino代码:

在主循环中:

if (strcmp(inData, "read")  == 0){
  Serial.println("SndEprom");
  delay(50);
  sendProm();
}

void sendProm(){
  for (int i=0; i <= 100; i++){
    // read a byte from the current address of the EEPROM
    value = EEPROM.read(address);

    Serial.print(address);
    Serial.print(",");
    Serial.print(value, DEC);
    Serial.println();

    // advance to the next address of the EEPROM
    address = address + 1;

    // there are only 512 bytes of EEPROM, from 0 to 511, so if we're
    // on address 512, wrap around to address 0


    delay(15);
  } 
  address = 0;
}

1 个答案:

答案 0 :(得分:1)

正如你在评论中所说的那样 - 你实际得到的字符串是“SndEprom” - 注意结尾处的空格。

要解决问题,请使用:

myString.trim().equals("SndEprom")