07-28-2009 05:34 AM
Hi all,
How can I add several types of data fields, to one TCP/IP packet? I'm trying to send (via TCP) several fields on numbers, the first two are unsigned integers (hexadecimal) and the rest are double precision. LV changes all the numbers to double precision if I put them in the same array. However, I must send them together (in one packet).
Does anyone know how to do this?
Thanks,
Yogev
07-28-2009 05:47 AM
Hi Yogev,
you can only send bytes/strings over tcp/ip so you have to convert your numbers into string. If you do this, then you can use different types.
Mike
07-28-2009 05:53 AM
Hi Mike
The program recieving this does not want to accept strings, but straightforward numerical data. Just the first 8 bytes are interpreted as Uint, then 6 bytes of double precision and another 4 bytes of Uint.
Is there no way of sending this without changing it to a string?
Thanks,
Yogev
07-28-2009 06:45 AM
Hi Yogev,
you send it definitifly as byte. One byte is a string of length one. So you can send it as string. You can use the type cast function to get a string from your data. The receiver will get the correct data if you send it in the expected format.
Mike
07-28-2009 06:53 AM - edited 07-28-2009 06:55 AM
Hi Yogev,
In LV, a string is simply a sequence of bytes; it isn't limited to printable ASCII characters and in particlar may contain null bytes, which a C string can't.
One way would be to build your numbers into a suitably-ordered cluster, and type cast that to a string which you send.
Rod.
EDIT: Can't type fast enough!
07-28-2009 08:50 AM
Thanks, a cluster did the job..
but now I send a double precision number, and it seems that the bytes where switched.. the first 4 bytes are been switched with the last 4 bytes, and vice versa.
this is causing error in the data received..
anyone knows how it can be fixed?
07-28-2009 08:59 AM
Flatten to string has an input to specify the endianess. You could also use swap bytes or swap words.
Ben
07-29-2009 04:24 AM
Hi Ben,
Thanks a lot for the suggestion.
Is there any function such as the swap word function that can be used for double precision data (64 bit)?
I need to swap the first 32 bits with the last 32 bit in double precision number..
Thanks again..
Yogev.
07-29-2009 07:17 AM
Convert dbl to U64 then use swap words. Swap Words is polymorphic and will adapt the the data type you prest to it.
Ben
07-29-2009 07:43 AM
Ben wrote:Convert dbl to U64 then use swap words. Swap Words is polymorphic and will adapt the the data type you prest to it.
Ben
Convert is a bad idea here.you want to typecast instead.
Rolf Kalbermatter