LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write 1D array to a binary file

Hello folks,

I am using LV2012 SP1  and RT 8.2.1. I am trying to save 1D SGL array into the binary file but the binary data does not make any sense.   However, if I convert to SGL to string and write a txt file I get the right values.

 

I have reviewed several dicussion on the subject and write to binary is a simple thing to do. Yet, I am stuck there 😞 and farnkly I do not what piece I am missing here. Any advice is highly appreciated.

 

I have attached both codes and output files

 

Regards,

Jose

   

0 Kudos
Message 1 of 9
(3,358 Views)

I don't think writing is a problem. How do you read the data?

-----

The best solution is the one you find it by yourself
0 Kudos
Message 2 of 9
(3,340 Views)

I'm not getting your 12967495 when I interpret your data.  I'm getting 114058 for the first single.  I've tried several things, but still can't get your value.

 

So I'm also thinking there is something wrong with your reading routine.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 9
(3,336 Views)

P@Anand thank you for your prompt reply. You have a point there. For a quick inspection I open the binary file with a text editor, (e.g. ultraedit, notepat), which prompt hexadecimal for each byte of data. I convert hexadecimal to decimal. In the image attached you can see on the right the conversion of the first four bytes. That number does not make any sense to me. Today I will have more time to dig into the issue. 

0 Kudos
Message 4 of 9
(3,335 Views)

0 Kudos
Message 5 of 9
(3,327 Views)

Ah, you interpreted the data as a U32 Big Endian.  Wrong on both counts.  The Single is a floating point format, so it won't make sense to you when you just look at the raw hex data.  Plus the LSB is first with Little Endian.

 

Make a quick VI to read the binary file with a Single as the data type and a -1 for the count (read all values).  Make sure that data matches what you put into the file write.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 9
(3,324 Views)

The writing is ok. As it has been pointed earlier reading is the problem. I am handling a lot of data. Reading back is more more complex than the piece above.

The structure of writing is: Four SGL values followed by three SGL arrays (3k Elements each) and another array (3k Elements) of I8. This block of data is repeated till the end of the file. Thus the block size is: 4x4 + 3x12k+6k = 4,2016 Bytes. If any of you have an elegant way to read back those values please let me know.

Thank you once again !!

0 Kudos
Message 7 of 9
(3,305 Views)

I would just chain together your reads inside of a While loop.  Stop the loop when you get an error (End Of File will come eventually).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 9
(3,299 Views)

Excellent 

0 Kudos
Message 9 of 9
(3,295 Views)