我有以下代码:
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
....我本以为这条线
打印(“发送设置为真”);
会跑掉的。我做错了什么?
谢谢,
罗琳
发送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;
}发布于 2014-02-09 22:40:31
正如您在注释中所说的--实际上得到的字符串是"SndEprom“--请注意末尾的空格。
要解决问题,请使用:
myString.trim().equals("SndEprom")https://stackoverflow.com/questions/21665624
复制相似问题