LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reading binary stream

Highlighted

 

I am trying to read a data packet from a serial connection (RS-232).  I managed to retrieve the data as a stringHowever, I got stuck since the data is encoded in binary formatI don't have a LabView driver but I do know the definition for the data

 

/* C definition for data packet, the real packet got much more fields */

struct {

    uint16 data[1024];

    uint32 time;

    char firmwareVersion[12];

    uint32 chksum;

}

 

I found a lot of examples to read binary data from a fileHowever, I don't want to save the string into a file to read it backI want to chart the data in real-time during the acquisitionI did found a sub-vi called "unflatten from string", but it didn't seem to work as expectedI really need something similar to "read binary from file" that accept a string as an inputOf course, I can cast my string into a array of uint8 and retrieve the data manually field by fieldHowever, this would be really tedious.

 

Decoding any binary format is a really straightforward operation in CSince LabView is an "easy too use" graphical language, there should be an easy way to do this.

 

Any ideas?

 

Patrick

 

0 Kudos
Message 1 of 5
(967 Views)

Hi PatF,

 

in the attachment you will find one way to get your data. There are probably nicer ways and it's up to you (you want to learn on your own, don't you?)

 

Btw. decoding is straightforward in LV too Smiley Wink

Message Edited by GerdW on 02-10-2010 08:26 PM
Best regards,
GerdW
CLAD expired, using LV2011SP1 + LV2017 (+LV2019 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 2 of 5
(943 Views)

Slight variation on GerdW's theme.  Again, when you go step-by-step it is not that hard.  In fact, what makes this seem hard is that you are crossing over from C structures to LV structures.  C code to deal with LV data structures looks a little ad hoc, just like LV code to deal C structures takes a little getting used to.  In fact, the hardest part here was faking the data string.

 

BinaryDataExample.png

 

&#$@^ it!  I specifically make a cluster constant to show the results and it gets blanked by the snippet.  Son of#@$!@

 

Edit:  should mention that I like unflatten because it is easy to deal with endianness of your data.

Message Edited by Darin.K on 02-10-2010 11:54 AM
Message 3 of 5
(931 Views)

My previous reply got accidently posted as a new thread.

 

Thank for the answer from GerdW.  Very clean vi.  I will to think a little more about the answer from Darin.K.

 

Patrick

0 Kudos
Message 4 of 5
(923 Views)
One thing you should be aware of is different endianness. The problem is that LabVIEW uses Big Endian format for its binary numbers, while most Windows programs use Little Endian format. It is no big deal. The number format is the same but the bytes has swapped place internally. And hence with wrong endian format your data will look like garbage


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 5 of 5
(907 Views)