String Event Issue

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;
  } 
}

Is the board sending 10 bytes or only 5 bytes?
00FF00012C looks suspiciously like 5 bytes written as hex. If this is correct try checking the numeric values of the bytes in the received char array.

Yes it sends "00 FF 00 01 2C" 5 Byts as Hex.

The sequence in polling every time and wait for a answer.
Checking... How?

andy75andreas:
Yes it sends "00 FF 00 01 2C" 5 Byts as Hex.
Checking... How?

Are you expecting to receive 10 (or 14) ASCII characters followed by a new line character?
Or are you expecting 5 bytes that have decimal values of 0, 255, 0, 1, 44?

I´m recive Ascii.

Your code limits the inputString to 5 characters so you will never see the 'C' character at position 10.

Ok, I can cange in the line "counter == 10" an so will I see the "C"

The line "if(strchr (char (inputString), 'C')) {" goes fail. (Compiler error)

andy75andreas:
The line "if(strchr (char (inputString), 'C')) {" goes fail. (Compiler error)

This page tells you how to search inside String objects