Forum : Compare Hex values to output sound
HEX : 02 Data Data Data CheckSum 03 , but Variable Length.
Fixed Value : value[0] = 0x02, value[last] = 0x03
1. Is the data item of the frame is ASCII Coded binary? If so, provide an example. 2. Assume that the following message frame has come from the remote sender:
021356753503 //STX Data1 Data2 Data3 CKSUM ETX
3. The above frame follows the below tansmission pattern where the digits of the message are in ASCII Coded bits except STX and ETX which remian in natural binary:
02 31 33 35 36 37 35 33 35 03
4. Program codes for receiver (untested):
#include<SoftwareSerial.h>
SoftwareSerial SUART(2, 3); //SRX = DPin-2, STX = DPin-3
bool flag = false;
char myData[20];
void setup()
{
Serial.begin(9600);
SUART.begin(9600);
}
void loop()
{
byte n = SUART.available(); //check that a data item has arrived from sender
if(n !=0)
{
if(flag != true)
{
byte x = SUART.read();
if(x == 0x02)
{
flag = true; //STX has arrived
}
}
else
{
byte m = SUART.readBytesUntil(0x03, myData, 20); //0x03 is not saved
mData[m] = '\0'; //insert null-charcater;
Serial.println(myData): //shows received string
//-- add codes to recompute CHKSUM and check validity of data
//-- add codes to process received string
memset(myData, 0x00, 20); //array is reset to 0s.
}
}
}
Compiler doesn't care how many, just that they are correctly matched... To be readable
that line needs more whitespace and put the "break;" on the next line.