LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuously reading data with checksum

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

Download All
0 Kudos
Message 1 of 2
(284 Views)

Hi elte,

 


@elte98 wrote:

I'm currently working on a solution to read out data from a device which sends a chunk of 9 bytes each 5 ms.

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:


Which kind of device and why does it even send "false values"?

Does that device allow to (re)trigger a fresh start with correct messages?

 


@elte98 wrote:

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


When you work with bytes (aka U8) then all you need to do is to add them and check for a resulting zero…

 


@elte98 wrote:

I attached my current VI for the simulation and some sample data. 


Unfortunately you use LV2023. Mind to share a down-converted version of your VI?

Most will say LV2021 or older, I prefer LV2019…

 


@elte98 wrote:

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.


When there is a random shift possible then you need to apply all the knowledge about the messages you can:

  • check 9 bytes for correct checksum
  • check some timestamp (or cycle counter) inside the message data
  • check for the next 9 bytes to yield a correct checksum too (so you are sure you a in sync again)…

How important is it to be in sync with your device? Is it safety related or is it "just" nice to have valid measurement data?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 2
(206 Views)