Your loop migt be too fast...and you don't wait for the transmissiin of "PRINT" is complete.
So it might be possible that the loop runs three times for example and the loop sees the following incoming data:
* "P"
* "RI"
* "NT"
But never the complete instruction.
Therefore you need to define a protocol.
I recommend to add a byte to detect the end of the instruction. Maybe [CR]
Then the complete instruction is "PRINT[CR]"
The input needs to be like this: incomingString = incomingString + Seriea.readString
Then run the loop as long as the string includes the [CR]..
Then process the string.
Your loop migt be too fast...and you don't wait for the transmissiin of "PRINT" is complete.
So it might be possible that the loop runs three times for example and the loop sees the following incoming data:
* "P"
* "RI"
* "NT"
But never the complete instruction.
Therefore you need to define a protocol.
I recommend to add a byte to detect the end of the instruction. Maybe [CR]
Then the complete instruction is "PRINT[CR]"
The input needs to be like this: incomingString = incomingString + Seriea.readString
Then run the loop as long as the string includes the [CR]..
Then process the string.
this is a simple solution, but it will hang on every single error.
And for sure it needs to clear "incomingBuffer"
Assume folowing buffer contents:
* "[garbage]PRINT[CR]" --> your "IF" won´t detect is as true, and it will never becoume true anymore. It hangs.
Independent of error: A LOW instead of a HIGH, a HIGH instead of a LOW, missing character or an added character... All will make that the application hangs.
The problem is the "=" operator.
There are other operators like: stringA contains stringB.
And i recomment to include a timeout: If for a dedicated time is no data transfer, then clear the incomingBuffer.