LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Split and "decode" a string

Hi,

I have just used LabView for a few weeks, and need some assistance on a project I'm working on. I've tried to find the answers on the forum, but can't find anything that match my problem.

I have 4 nodes/sensors with two channels each. They are connected wireless to a base station, which is connected to my computer Com port (Serial port).

 

I've managed to make a program that reads the serial port data string, but I need some help splitting the string and sort them into groups. 

 

When the transmitters samples on a high rate, the string I read can be up to 1500 bytes long, but the length of the string is not always the same.

 

Example (Hex display): 

"AA07 0401 830A 020C 6A03 25D6 02D8 0008 1DCB 02F1 AA07 0401 810A 020C 6A03 25D9 02DB 000E 14C2 02FB AA07 0401 820A 020C 6A03 25D8 02E8 0010 1CCA 030A AA07 0401 830A 020C 6A03 25D7 02D8 0006 1DCB 02F0 AA07 0401 810A 020C 6A03 25DA 02DB 0014 14C2 0302 AA07 0401 820A 020C 6A03 25D9 02E8 0011 1CCA 030C AA07 0401 830A 020C 6A03 25D8 02D8 0007 1DCB 02F2 AA07 0401 810A 020C 6A03 25DB 02DB 0010 14C2 02FF AA07 0401 830A 020C 6A03 25D6 02D8 0008 1DCB 02F1 AA07 0401 810A 020C 6A03 25D9 02DB 000E 14C2 02FB AA07 0401 820A 020C 6A03 25D8 02E8 0010 1CCA 030A AA07 0401 830A 020C 6A03 25D7 02D8 0006 1DCB 02F0 AA07 0401 810A 020C 6A03 25DA 02DB 0014 14C2 0302 AA07 0401 820A 020C 6A03 25D9 02E8 0011 1CCA 030C AA07 0401 830A 020C 6A03 25D8 02D8 0007 1DCB 02F2 AA07 0401 810A 020C 6A03 25DB 02DB 0010 14C2 02FF AA07 0401 830A 020C 6A03 25D6 02D8 0008 1DCB 02F1................." 

 

Each sensor packet consist of 20 bytes, and every packet starts with AA07.

 

So from the example above the first packet from the first sensor is: 

AA07 0401 830A 020C 6A03 25D6 02D8 0008 1DCB 02F1

 

The second packet is:

AA07 0401 810A 020C 6A03 25D9 02DB 000E 14C2 02FB

 

 

Byte number 4 (MSB) and byte number 5 (LSB) is the address for the node

Byte number 13 (MSB) and byte number 14 (LSB) is the value for channel 1

Byte number 15 (MSB) and byte number 16(LSB) is the value for channel 2.  

 

 

The final goal is to read both channels on all four nodes/transmitters simultaneously,  and present them in different charts. 

 

I have managed to make a VI that's able to read one single node packet of 20 bytes and "decode" it into node address and the value of channel 1, but I've not managed to make a VI that can read the whole example string.. 

 

I hope there's someone who could help me. 

 

Thanks

Olav

 

 


 

 

 

Download All
0 Kudos
Message 1 of 4
(1,738 Views)

Olav,

 

The basic idea is to operate on the string in a loop. Locate the AA07 bytes then extract the remainder of the packet.  Decode that packet. On the next iteration of the loop locate and decode the next packet.  Use a shift register to pass the remaining string to the next iteration.

 

Lynn

0 Kudos
Message 2 of 4
(1,732 Views)

If you dont need the AA07 anymore, or if you are post processing the resulting array in a loop, you could try this.

string to array.png


CLA CTAChampion
Subscribe to our Test Automation user group: UK Test Automation Group
Message 3 of 4
(1,727 Views)

The danger with that is if AA07 are valid values in the payload, then you windup breaking up a packet there.

0 Kudos
Message 4 of 4
(1,721 Views)