06-19-2014 07:04 AM - edited 06-19-2014 07:07 AM
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
06-19-2014 07:29 AM
I don't think writing is a problem. How do you read the data?
06-19-2014 07:36 AM
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.
06-19-2014 07:36 AM
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.
06-19-2014 07:39 AM
@ crossrulz. I was not getting that 😞 How did you get the first single? Thanks!!
06-19-2014 07:43 AM - edited 06-19-2014 07:46 AM
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.
06-19-2014 09:16 AM
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.
06-19-2014 09:30 AM - edited 06-19-2014 09:31 AM
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).
06-19-2014 09:35 AM
Excellent crossrulz! I was half way on doing similar thing too 🙂 I deeply appreciate your feedback!