The tutorial was a great help. I succeeded to use the startmarker and filter the code. Only i'm not a champion in programming. So i still have two problem now. First i want to use the start of message and the number of bytes both as the startmarker i tryed to put them in a array but it didn't worked. Next i tryed different ways to count for the 19 bytes for the endmarker. But here i didn't succeeded eigther. Tommorrow another day for succes but if you guys have a tip great thanks.
AC 13 301B 00 003436 0F5B0F6E0F6A001F0065003E5E
0xAC: start of message
0x13: number of bytes to follow
// Example 6 - Receiving binary data
const byte numBytes = 32;
byte receivedBytes[numBytes];
byte numReceived = 0;
boolean newData = false;
void setup() {
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}
void loop() {
recvBytesWithStartEndMarkers();
showNewData();
}
void recvBytesWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
byte startMarker[] = {0xAC, 0x13};
byte endCount = 0;
byte rb;
while (Serial.available() > 0 && newData == false) {
rb = Serial.read();
if (recvInProgress == true)
{
if (endCount != 19)
{
receivedBytes[ndx] = endCount;
ndx++;
endCount++;
if (ndx >= numBytes)
{
ndx = numBytes - 1;
}
}
else {
receivedBytes[ndx] = '\0'; // terminate the string
recvInProgress = false;
numReceived = ndx; // save the number for use when printing
ndx = 0;
newData = true;
}
}
else if (rb == sizeof(startMarker))
{
recvInProgress = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in (HEX values)... ");
for (byte n = 0; n < numReceived; n++) {
Serial.print(receivedBytes[n], HEX);
Serial.print(' ');
}
Serial.println();
newData = false;
}
}