Hi.
I am using Seeeduino Xiao with String variable (inStr) initialized by NULL. However I got a compilation error.
C:\Projects\Payload simulator\Codes\Arduino\pcg_01\pcg_01.ino: In member function 'void Serialport::readLine()':
C:\Projects\Payload simulator\Codes\Arduino\pcg_01\pcg_01.ino:151:18: error: conversion from 'int' to 'String' is ambiguous
String inStr = NULL;
^
In file included from C:\Users\tonyz\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\cores\arduino/Arduino.h:80:0,
from C:\Users\tonyz\AppData\Local\arduino\sketches\73B329A8803FC33FB337E6F86C4CDBFD\sketch\pcg_01.ino.cpp:1:
C:\Users\tonyz\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\cores\arduino/WString.h:61:2: note: candidate: String::String(const __FlashStringHelper*)
String(const __FlashStringHelper *str);
^~~~~~
C:\Users\tonyz\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\cores\arduino/WString.h:59:2: note: candidate: String::String(const char*)
String(const char *cstr = "");
^~~~~~
exit status 1
Compilation error: conversion from 'int' to 'String' is ambiguous
I assume that assigning NULL to a String variable is acceptable, but not very sure. below are my code.
class Serialport {
public:
char inBuffer[64] = {0};
char outBuffer[64] = {0};
bool inputFlag;
bool outputFlag;
char inChar;
String inStr;
Serialport() { // class constructor
inBuffer[0] = '\0';
outBuffer[0] = '\0';
inputFlag = false;
outputFlag = false;
inChar= NULL;
inStr = NULL;
}
char readChar();
void readLine();
void sendLine();
};
char Serialport::readChar() { //function to read a char in the placeholder and return it if sucessfully read, or return '0x0'
char inChar = NULL;
if (Serial.available() > 0) {
inChar = Serial.read();
return inChar;
}
return inChar;
}
void Serialport::readLine() { //function to read a line ended with '\n' into inBuffer and set the flag if sucssfully read.
inStr = NULL;
if (Serial.available()>0) {
inStr = Serial.readStringUntil(EOL); // this is blocking read.
}
}
the compilation indicates both lines of "inStr = NULL" have error.
any help is greatly appreciated, Thanks.