LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a Binary String from a Configuration File

Solved!
Go to solution

Is it possible to read a U8 integer from a conifguration file instead of the standard U32? I'm storing a binary string in my file and need to read it in as an 8 bit string, for instance "10100000" needs to be read in as such. Currently I'm trying to typecast it as it comes out, but my VI stalls when it tries to convert.

Capture.PNG

I would upload my VI if I could, but because I can't I'll provide a brief explanation - this code cycles through a previously declared number of variables in the configuration file, all just named letters 'a','b','c', ... and then fills an array with all of the binary strings read from the file.

0 Kudos
Message 1 of 4
(2,638 Views)

Can you just read it as a string? You can turn strings into byte arrays and get your U8s back.

 

Also, what do you mean that your VI stalls when it tries to convert? Is LabVIEW hanging on the typecast function?

Matt J | National Instruments | CLA
0 Kudos
Message 2 of 4
(2,624 Views)

After using a 'to U8' function instead of a typecast and it appears to work now... Not sure why but...

0 Kudos
Message 3 of 4
(2,614 Views)
Solution
Accepted by topic author reesl

Typecasting a U32 to a U8 involves two steps, first the U32 is converted to Big Endian format, and then the result is interpreted as a U8.

 

For example a U32 with value 128 will be converted to 4 bytes:  0x00 0x00 0x00 0x80 and then interpreting as a U8 just uses the first byte and you get 0 for all but quite large U32 values.

 

Using the conversion function coerces the value instead which is precisely what you want to do here.  That means it uses the last byte instead of the first and you get 0x80 or 128.

Message 4 of 4
(2,608 Views)