03-24-2015 04:32 PM
I have an instrument that sends the information in a 4-byte array that represents a 32-bit floating point number in little endian notation. How do I join them into a single number?
03-24-2015 04:49 PM
Use the Unflatten From String. It has an input for the Endianness, make sure that is set to Little Endian.
03-30-2015 03:34 PM
Thank you, but here is where I get lost. The data from the instrument is sent in 5 bytes in ASCII and I use the string subset to drop the first letter, the remaining 4 characters represent a 32-bit floating point number in little endian. It looks like I then need to convert the ASCII to binary before input into the unflatten from string. Suggestions?
03-30-2015 03:55 PM
@loman247 wrote:
It looks like I then need to convert the ASCII to binary before input into the unflatten from string. Suggestions?
You don't need to do any conversion. Wire the 4-character string to the string input of Unflatten from String.
Unless your instrument is actually sending the values as text, but then the maximum value would be 9999 which would fit in 16-bits and endianness would be irrelevant, so that's probably not what's happening.
03-30-2015 04:03 PM
You got the instrument rresponse from a VISA Read, I suppose, which returns string data, and you said you'd parsed off an initial character.
Unflatten From String takes a LabVIEW string datatype as input. You also need to give it a typing wire so it knows what type the output needed is. You'll want to wire a floating-point single-precision constant (SGL), value irrelevant, to do this. MAKE SURE you set the constant's datatype correctly.
Apart from that, follow the earlier advice - wire in the other constants for little-endian byte ordering, and a false constant for "data includes... size". You really should take the error out teminal too, and do some conditional processing based on error status!
Dave
04-01-2015 03:50 PM - edited 04-01-2015 03:52 PM
Thanks again for your assistance. I have attached a shot of my VI, should be seeing something closer to 0...hoping I am not embarrassing myself :/.
04-01-2015 03:58 PM
If you want to unflatten to a single-precision value, then why are you unflattening to an int? Change the numeric representation of the Type input to a SGL (right-click the numeric constant), and get rid of the conversion that follows.
Also, for byte order, it's easier to use the built-in enumeration than a numeric constant (delete the "2", right-click, create a constant).
The "to single-precision" conversion converts the numeric value, NOT the bits, which is why this is failing. If you start with an integer with the value of 5, you'll get a single-precision value of 5, not a single-precision value that has the same bits as the integer. What you're doing here is taking your bits, converting them to an integer, then asking for a single-precision representation of that number - where what you should be doing is taking those bits and interpreting them directly as a single-precision value.
04-01-2015 04:35 PM
Like nathand said. And I said it too... in all caps. MAKE SURE you set the constant's datatype to SGL. Again, the value is irrelevant, it's just a typing wire.
04-01-2015 04:49 PM
Let's see, if I work backwards from your broken example...
I square your displayed value;
convert it to a U32 -guessing here, but that's what a dropped constant will assume unless you right-click and change representation [or type a fractional value in]);
flatten the U32 back to string (little-endian);
unflatten the string back to SGL (again, LE);
and take the sqrt() of that, I get 2.56584... is that a value you'd expect?
Dave