06-07-2019 09:18 AM
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.
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.
Solved! Go to Solution.
06-07-2019 09:31 AM
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?
06-07-2019 09:47 AM
After using a 'to U8' function instead of a typecast and it appears to work now... Not sure why but...
06-07-2019 10:01 AM
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.