LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading 0x00 in binary file as space 0x20

Solved!
Go to solution
Trying to read in binary file that contains single precision floating point hex values. Using the Read from Binary File function and storing values in an array. The problem is that LabVIEW reads the null character (0x00) as a space character (0x20). For example, read in 3F800000 which is 1.0 in floating point. The output in LabVIEW reads 1.00098 (rounded by LabVIEW), or a hex value of 3F80201C. The unrounded hex value should be 3F802020 for this number. Is this a known issue and are there any solutions? I have attached a jpeg of my block diagram as well as the binary input data. I could not upload a .bin file so I saved it as .txt. Thanks in advance.
Download All
0 Kudos
Message 1 of 20
(5,942 Views)

I see a grey coercion dot on your "built array" node and another one on the array indicator. Maybe you should double-check the representation of all your diagram constants. Looks like you initialize the array as DBL. Things like that would NOT happen if you would use only a single diagram constant and use it for both the read and initiaize function. You can branch the wire.

 

Please attach the real VI instead of a picture. Thanks! 🙂

Message Edited by altenbach on 11-13-2008 11:37 AM
0 Kudos
Message 2 of 20
(5,931 Views)
Sorry about that, here it is
0 Kudos
Message 3 of 20
(5,927 Views)
Thank you, by the wa, and you are correct, I accidentally initialized the array as a DBL; however, I changed it to single and it made no difference. Any other suggestions?
0 Kudos
Message 4 of 20
(5,925 Views)

Your file contains space characters and not null characters. How are you wrting it?

 

If you are only interested in the first two bytes, you could read it as U32, mask off the desired bytes, and cast to SGL.

Message Edited by altenbach on 11-13-2008 11:59 AM
0 Kudos
Message 5 of 20
(5,921 Views)

altenbach wrote:

If you are only interested in the first two bytes, you could read it as U32, mask off the desired bytes, and cast to SGL.


Here's a quick example for this.

 

Message Edited by altenbach on 11-13-2008 12:05 PM
0 Kudos
Message 6 of 20
(5,914 Views)
If you open the original binary file in a hex editor, it will show that those are not spaces but null characters. They are recoginzed as spaces when converted to .txt files. I believe that is how LabVIEW is interpreting these files.
0 Kudos
Message 7 of 20
(5,910 Views)
What is that function you're using to mask off the bytes?
0 Kudos
Message 8 of 20
(5,906 Views)

MonstorBak wrote:
What is that function you're using to mask off the bytes?

 

That is an And gate with a U32 configured as hex display to specify the mask.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 20
(5,897 Views)

Well, the file you have attached does NOT contain null characters. If you have a better file, zip it up and attach it. Thanks.

 

The function is a logical AND from the boolean palette. When used with integers, it will do a bitwise operation. Still, I doubt you want to do that. using only 2 bytes for a SGL seems to throw away way too much. You only have 7 useful bits left for the mantissa.

0 Kudos
Message 10 of 20
(5,896 Views)