我有以下代码:开始在处理工作和字符串不比较
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
....
我会认为line
print(“sending set true”);
已经运行。我做错了什么?
感谢,
罗兰
代码Arduino的发送EEPROM数据:
在主循环:
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;
}
你确定'myString'等于' “SndEprom”'?检查它是否有尾随空格。 – Christian
try myString.trim()。equals(“SndEprom”) –
当我尝试了你的建议时,检查'myString'是否与'print(“[”+ myString +“]”)' – wolfrevo