|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
UDP from C++ to Labview
Hey everyone,
I've been trying to send a structure from C to labview. My structure is composed of 3 variables, two integers and one float. I can get labview to receive the two integer values however, it cannot interpret the float properly and gives me a number like 7.5264 e-41. I feel like the problem is how labview interprets a float compared to a c++ on my linux machine. just thought ill post this and see if anyone knows what my problem is? Thanks |
|
#2
|
|||
|
|||
|
Re: UDP from C++ to Labview
LV and most languages support more than one size of floating point number. In particular, the single precision (4 byte), double precision (8 byte), and extended precision (10 or more) are pretty common. In C/C++ they will usually be called single, double, and long double. Sometimes you will see double doubles and other odd numeric types as well.
Check that the size of all three elements are correct, as misalignment of one of the earlier elements will affect the later elements. The other factor causing this could be the byte order. Multibyte numbers can have their bytes transmitted either left-to-right, or right-to-left. This is often called little-endian and big-endian. It comes into play with memory architectures as well as transmission. By default, LabVIEW always assumes that data coming in from network and file are big-endian and does the work on little-endian machines like Intel to convert back and forth. If your data is in little endian format, then LV will load the bytes in the wrong order. If you are using the unflatten from string node, try wiring up the other byte-order parameter and see if that fixes it. Greg McKaskle |
|
#3
|
|||
|
|||
|
Re: UDP from C++ to Labview
Hi Greg,
I've verified that the size of all the elements are correct, and I have tried the different byte orders with no luck. Any other ideas? Thanks again for helping me out, |
|
#4
|
||||
|
||||
|
Re: UDP from C++ to Labview
single-precision is usually called float in C/C++
|
|
#5
|
|||
|
|||
|
Re: UDP from C++ to Labview
To test try this just to make sure you don't run into any surprises. A long is sometimes 4 bytes just like an int.
Code:
printf("%d %d %d\n", sizeof(float), sizeof(double), sizeof(long double));
Code:
void writeDouble(std::vector<char>* packet, double value)
{
#ifndef ENABLE_TELEMETRY
return;
#endif
long long adjustedValue = ((long long)(value*1000000)); //send floating point as integer * 1000000
unsigned char *dblPtr = (unsigned char*)&adjustedValue;
for(int i = 0; i < sizeof(long long); i++)
{
packet->push_back(*dblPtr);
dblPtr++;
}
}
|
|
#6
|
|||
|
|||
|
Re: UDP from C++ to Labview
thanks everyone for your help!
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|