Go to Post I know the code works, I wrote it! It must be a hardware problem. - buss [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-11-2012, 07:41
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,748
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
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
  #2   Spotlight this post!  
Unread 03-11-2012, 10:58
moler moler is offline
Registered User
FRC #0772
 
Join Date: Jul 2009
Location: Canada
Posts: 13
moler is an unknown quantity at this point
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,
  #3   Spotlight this post!  
Unread 03-11-2012, 21:37
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: UDP from C++ to Labview

Quote:
Originally Posted by Greg McKaskle View Post
In C/C++ they will usually be called single, double, and long double.
single-precision is usually called float in C/C++
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
  #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.
  #5   Spotlight this post!  
Unread 04-11-2012, 01:09
moler moler is offline
Registered User
FRC #0772
 
Join Date: Jul 2009
Location: Canada
Posts: 13
moler is an unknown quantity at this point
Re: UDP from C++ to Labview

thanks everyone for your help!
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:06.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi