Hello,
I have a board that sends "00FF00012C" via a serial interface when I switch on.
I have to answer this message with "D300FF".
When I send the incoming string to the PC, it arrives.
But for some reason I can't search for any characters in the string.
Hardware: Arduino Due (SerialEvent1 does not work with the hardware!)
I did not write the answer yet, because the evaluation does not work yet.
Here comes an error message... Why?
if(strchr(char (inputString), 'C')) {
String inputString = ""; // a String to hold incoming data
char StartString[] = "2C";
bool stringComplete = false; // whether the string is complete
String outputString = "D304"; // a String to hold incoming data
int counter = 0;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
// initialize serial:
Serial.begin(9600);
Serial1.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
}
void loop() {
while (Serial1.available()) {
digitalWrite(LED_BUILTIN, HIGH); //turn LED on
// get the new byte:
char inChar = (char)Serial1.read();
// add it to the inputString:
inputString += inChar;
counter++;
// if the incoming character is a newline, set a flag so the main loop can
// do something about it:
//if (inChar == "2C" ) { // '/n'
if (counter == 5) {
stringComplete = true;
}
}
// print the string when a newline arrives:
if (stringComplete) {
if(strchr(char (inputString), 'C')) {
Serial.print(inputString);
digitalWrite(LED_BUILTIN, LOW); //turn LED off
}
// clear the string:
inputString = "";
stringComplete = false;
counter = 0;
}
}