LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read mixed type C binary file

Solved!
Go to solution

Hello,

 

I have script program, what can output the desired data in csv ASCII, and in binary file format. Sometimes not all of the valuable digits are printed out to the csv file, therefore I need to read out the data from the binary file.

I have atttached what I have so far, and also a small csv and the bin file, containing the same data.

 

I can read out the first integer value (2), but the second data type is a string, and I cannot read this one out...I get end of file error, I guess because the type is wrong, or I guess I have to read the data out in a different way?

 

Based what I see in the csv file, the structure of the binary should be the following:

integer, string, float, and repeated again every line in the csv...?

 

thanks for advice!

 

ps.: the website does not allow me to upload the files, so here they are:

https://dl.dropboxusercontent.com/u/8148153/Read%20Binary%20File.vi

https://dl.dropboxusercontent.com/u/8148153/init_in_water.csv

https://dl.dropboxusercontent.com/u/8148153/init_in_water.bin

0 Kudos
Message 1 of 5
(3,838 Views)

Your binary data looks like it is well behaved. You can easily read n number of bytes from the file (or buffer if you read the entire contents of the file at one time), separate the various components and place them into a cluster. You will need to determine how many bytes are being used to store the string. You will also need to determine what format the floating point number is stored in. The last thing you will need to determine is the byte order of the numeric data. LabVIEW does everything in network byte order (big endian). The string data should be no issue. I suspect that your data is little endian and the first 4 bytes are the integer value. The next 8 bytes are the string with NULL characters padding the unused space. The last 12 bytes are the floating point number.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 5
(3,815 Views)
Solution
Accepted by topic author Blokk

Here is a basic example of what I am referring to. This is correctly parsing the integer and the string. The floating point number at the end is not decoding correctly. I tested in on the first entry in your binary file. If you have access to the code which is generating this data you can see exactly what format the data is. Your data appears to be 22 bytes in length.

 

Binary conversion.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 3 of 5
(3,804 Views)

Thanks for the help!

I have attached my test VI. I also cannot get value out from the last float part. Besides, the "Match regular expression" function throws an error:

Error -4702 occurred at Error occurred during regular expression match.
Possible reason(s):
LabVIEW:  One of the string parameters contains a null character. LabVIEW does not support null characters for regular expression matching.

 Actually even of this error, it works and gives out the string value...(therefore I do not wire through the error wire)

What is the reason of this error? And why it works even though?

 

Also I try to figure out the last floating number problem in the first 22 bytes...

 

ps.: Could someone at NI fix the file upload bug (The contents of the attachment doesn't match its file type.) of the discussion forum? this is getting be ridiculous...

dropbox: https://dl.dropboxusercontent.com/u/8148153/Read%20Binary%20File_mod.vi

0 Kudos
Message 4 of 5
(3,783 Views)

okey, with a little calculation I figured out the data structure:

the whole binary file is 1219 byte long.

I have 53 lines in the csv file, and I know that, the int and the float are both 4 bytes, so the length of the strings is:

 

(1219 - (53*2*4) ) / 53 = 15 byte.

 

I modified my code, and it works nice 🙂

thanks again!

0 Kudos
Message 5 of 5
(3,773 Views)