View Single Post
  #4   Spotlight this post!  
Unread 03-11-2012, 22:22
kwojcik kwojcik is offline
Registered User
no team
Team Role: Mentor
 
Join Date: Sep 2008
Rookie Year: 2009
Location: California
Posts: 24
kwojcik is a splendid one to beholdkwojcik is a splendid one to beholdkwojcik is a splendid one to beholdkwojcik is a splendid one to beholdkwojcik is a splendid one to beholdkwojcik is a splendid one to behold
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));
If you are still having trouble, try multiplying your double by 1000000, casting it to a long long and sending that over the socket. Then divide by 1000000 on the other side. But beware, if you want to keep decent precision doing this, you need to use long long because a long is only 4 bytes on the robot in c++! I did exactly this for a custom telemetry client I wrote
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++;
	}
}
If all else fails you can send it as a string. Usually fool-proof.