04-17-2025 04:23 AM
Hey everyone!
I'm currently working on a solution to read out data from a device which sends a chunk of 9 bytes each 5 ms.
The first 8 bytes include a timestamp and my measurement data. The last byte in combination with the previous 8 bytes serves as a checksum and if the sum of byte 1 to byte 9 is a multiple of 256 the packet is valid.
So for example:
143 12 0 16 0 232 0 16 93 --> 512/256 = 2 --> packet is valid
If it always sends the data like this I would just read out 9 bytes, check if the packet is valid, and repeat it until I want to stop the measurement. My problem is that sometimes there are false values transmitted which lead to a shift in the values:
143 12 0 16 0 232 0 16 93
143 13 0 0 0 0 0 0 0
0 2 0 232 0 2 120 143 14
0 14 0 232 0 14 95 143 15
I don't really care about losing one measurement value (in this case between 143 13 .... and 143 14 .... ) but the shift means I can't just always take 9 values and somehow need to synchronize them after a shift. The shift is also not always the same.
Another problem I faced is that sometimes when I try synchronizing the data to correct chunks of 9 again I create false packets with a valid checksum so for example for this sequence:
143 12 0 16 0 232 0 16 93
143 . . . . . . . . . .
Both 143 12 0 16 0 232 0 16 93 and 12 0 16 0 232 0 16 93 143 would give a valid packet, but only the first one will actually yield correct measurement data.
I have a rather lengthy solution which works well for pre-recorded values but struggles when using it for a live measurement. I check for a valid packet and if its not valid cycle through the coming measurement data byte by byte, compare them to the previous timestamp bytes and look for a new valid packet. In my live measurement approach I basically tried using the same program, but instead of reading the data from an array I read it from the COM port.
Maybe I'm thinking a bit too complicated, so does anybody have advice on how to approach this problem?
I attached my current VI for the simulation and some sample data.
Best regards and thanks in advance