Robin2:
If the start marker is 0xF2 and the end marker is 0xF6 then put those in my 3rd example and it should work.You will probably also need to change the datatypes from char to byte.
...R
I test your 3rd example : If an other solar panel reply to the modem, somewhere, there will be probably a 0xF6 in data
so , the ideal would be to look at what happens between start: 0xF2 and the end: 0xFD0808F6
i'm near from the goal but i got an issue with byte lenth .... this is the result :
byte startMarker = 0xF2;
byte endMarker = 0xFD0808F6; <----------------- warning: large integer implicitly truncated to unsigned type
Rx (HEX): 40 5 65 FD 8 8
Byte START: F2 <------ good !
Byte 0: 40 ok
Byte 1: 5 ok
Byte 2: 65 ok
Byte 3: FD
Byte 4: 8
Byte 5: 8
Byte END: F6 <------------ ISSUE: i think is lenth of byte problem: How to read END marker FD0808F6 ?
the code :
byte startMarker = 0xF2;
byte endMarker = 0xFD0808F6;
const byte numBytes = 10;
byte receivedBytes[numBytes];
byte numReceived = 0;
boolean newData = false;
//===================================
//= SETUP =
//===================================
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(9600);//moniteur serie
Serial1.begin(9600);//reception wireless
delay(3000); //delai pour ouvrir COM8 apres televersement
//========== LED =========
pinMode(ledInt, OUTPUT);
digitalWrite(ledInt, HIGH);// Éteindre la LED
Serial.println(F("+++ RxBinaryData +++"));
} // FIN de setup
//===================================
//= LOOP =
//===================================
void loop() {
recvBytesWithStartEndMarkers();
showNewData();
} //FIN de loop
//=================================================================================
//====================== AUTRES FONCTIONS ==================================
//================================================================================
void recvBytesWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
byte rb;
while (Serial1.available() > 0 && newData == false) {//Rx: F2 40 05 65 FD 08 08 F6
rb = Serial1.read();
if (recvInProgress == true) {
if (rb != endMarker) {
receivedBytes[ndx] = rb;
ndx++;
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;
}
}//FIN de recinprogress true
else if (rb == startMarker) {
recvInProgress = true;
}
}//FIN de while serial1
}// FIN DE FONCTION
//================================================================================
void showNewData() {
if (newData == true) {
Serial.print("Rx (HEX): ");
for (byte n = 0; n < numReceived; n++) {
Serial.print(receivedBytes[n], HEX);
Serial.print(' ');
}//FIN de serial print N Bytes
//pr2: display Bytes
///*
Serial.print("\nByte START: "); Serial.print(startMarker, HEX);
Serial.print("\nByte 0: "); Serial.print(receivedBytes[0], HEX);
Serial.print("\nByte 1: "); Serial.print(receivedBytes[1], HEX);
Serial.print("\nByte 2: "); Serial.print(receivedBytes[2], HEX);
Serial.print("\nByte 3: "); Serial.print(receivedBytes[3], HEX);
Serial.print("\nByte 4: "); Serial.print(receivedBytes[4], HEX);
Serial.print("\nByte 5: "); Serial.print(receivedBytes[5], HEX);
Serial.print("\nByte END: "); Serial.println(endMarker, HEX);
//*/
Serial.println();
newData = false;
}//FIN de new data true
}// FIN DE FONCTION
IN RESUME i want :
when see 0xF2 :
begin to read ..... and count number of Bytes ....
when see 0xFD0808F6 :
stop reading + store the data between 0xF2 and 0xFD0808F6 on a variable "Data", + the lenght of the "Data" in a variable "NumberOfBytes" ...... That will be greaaat !!