For my application I am communicating to a motor driver via the serial monitor by sending strings. To do this I am using a serialEvent() function to build the string before sending it off to Serial3. It looks something like this.
I am having an issue whereby I want to interpret the string and if the string is required to something (someAction), it does, else it sends the command to Serial3. Something like:
The problem is that the code (possibly the string reconstruction) cannot interpret the "someAction" string and immediately sends it off to Serial3. I am sure this problem has to do with data structure but I cannot figure it out. I also tried adding a line feed, but that is not working.
If the message is to be terminated with the newline character, why not use something like
#define MESSAGESIZE 20 // Whatever the size needs to be
char message[MESSAGESIZE + 1]; // Room for terminating null
// setup() and loop() code...
// Code in loop()
int charsRead;
while (Serial.available() > 0) {
charsRead = Serial.readBytesUntil('\n', message, MESSAGESIZE);
message[charsRead] = '\0'; // Make it a string...
commandComplete = true;
}
// rest of code