我有以下代碼:開始在處理工作和字符串不比較
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