12-30-2016 07:33 AM - edited 12-30-2016 07:36 AM
Hello
I'm a newbie and use a union code to send a double number to labview using arduino uno .
this code
union {
double f;
byte b[4];
} stuff;
stuff.f = number to send;
payload[1] = stuff.b[0];
payload[2] = stuff.b[1];
payload[3] = stuff.b[2];
payload[4] = stuff.b[3];
and in my Labview vi i receive:
sending number payload 1 payload 2 payload 3 payload 4
0 0 0 0 0
1 0 0 128 63
2 0 0 0 64
3 0 0 64 64
4 0 0 128 64
3,14159 208 15 73 64
how can I get the double in my vi??? I've tried join numbers ..and didn't work....
thanks
Solved! Go to Solution.
12-31-2016 04:36 PM
Well, there are some things very wrong here. What does a "dbl" mean to you? To LabVIEW, this is a Double-Precision Float, which is a 64-bit, 8-byte representation of a number in floating-point format. To represent it, you would need to send 8 bytes.
There is also the LabVIEW "sgl", a Single-Precision 32-bit, 4-byte floating-point representation. If your Arduino number really occupies 4 bytes, it is what LabVIEW would call a "sgl". I don't know what the Arduino code you quote means, but "double f" seems to be a 4-byte float.
Next, byte order. There is something call "endian", referring to "big-endian" and "little-endian", which says "Which end in a multi-byte number representation is stored first, in the lowest byte address". LabVIEW stores Big-Endian, that is, the single-precision number 3.0 results in a 4-byte array 64, 64, 0, 0.
Note that your example code gives what appear to be that "double[3]" is 0, 0, 64, 64. So if you attempt to take these four bytes into an array in the order 0, 0, 64, 64 (the value at index 0 is 0, at index 3 is 64), you'd need to reverse the array before trying to convert it to a Sgl. [It doesn't have enough bytes to be a Dbl].
So here is some code (with part blacked out for you to fill in yourself -- the answers are all in this post).
The first shows a Sgl, 3.14159, run through a TypeCast into an Array of Bytes (the thing going into the TypeCast is ... an Array of U8, or Byte). The output is brought to an Array of Bytes indicators (which you can see is an Array of U8), then another TypeCast (the 0 is of type Sgl), and the Sgl Result that come back (guess what -- it is 3.14159). The second line is the array you suggested for 3.14159. When I run this code, I get (in the variable "Pi?") 3.14159. What's hidden in the Black Box?
Bob Schor
12-31-2016 05:00 PM - edited 12-31-2016 05:06 PM
Thank you Bob
a nice bunch of infotmation for a newbie like me.
I'll try your concepts.
I'll let you know if the sgl works ( i believe this is the main problem..i was using I32 to convert it...and reverse order...)
thanks again..and happy new year
12-31-2016 07:35 PM
... and a happy new year to you, too.
Bob Schor