Good evening all.
I`m trying to receive the following serial communication from a device.
The device sents hex of a value of AA 78 0 1 CC 33 C3 3C or AA 78 0 0 CC 33 C3 3C depending on what page I am on.
Using the code below:
const unsigned int MAX_MESSAGE_LENGTH = 12;
void setup() {
Serial.begin(115200);
Serial3.begin(115200);
}
void loop() {
//Check to see if anything is available in the serial receive buffer
while (Serial3.available() > 0)
{
//Create a place to hold the incoming message
static char message[MAX_MESSAGE_LENGTH];
static unsigned int message_pos = 0;
//Read the next available byte in the serial receive buffer
char inByte = Serial3.read();
//Message coming in (check not terminating character) and guard for over message size
if ( inByte != '\n' && (message_pos < MAX_MESSAGE_LENGTH - 1) )
{
//Add the incoming byte to our message
message[message_pos] = inByte;
message_pos++;
}
//Full message received...
else
{
//Add null character to string
message[message_pos] = '\0';
//Print the message (or do other things)
Serial.println(message);
//Reset for the next message
message_pos = 0;
}
}
}
I get:
3�<�x
y
3�<�y
x
3�<�x
y
3�<�y
x
3�<�x
y
3�<�y
x
This obviously isn`t what the display sent
It was suggested before that we cannot create string because the of the "0" in the code which is read as terminator.
My question is:
How can I receive an array / string from the HEX Serial message mentioned above so that the serial receive match what the display sent?
Thanks in advace.