02-10-2010 12:12 PM
I am trying to read a data packet from a serial connection (RS-232). I managed to retrieve the data as a string. However, I got stuck since the data is encoded in binary format. I 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 file. However, I don't want to save the string into a file to read it back. I want to chart the data in real-time during the acquisition. I did found a sub-vi called "unflatten from string", but it didn't seem to work as expected. I really need something similar to "read binary from file" that accept a string as an input. Of course, I can cast my string into a array of uint8 and retrieve the data manually field by field. However, this would be really tedious.
Decoding any binary format is a really straightforward operation in C. Since LabView is an "easy too use" graphical language, there should be an easy way to do this.
Any ideas?
Patrick
02-10-2010 01:26 PM - edited 02-10-2010 01:26 PM
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
02-10-2010 01:52 PM - edited 02-10-2010 01:54 PM
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.
&#$@^ 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.
02-10-2010 02:01 PM
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
02-10-2010 04:37 PM