LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Different types of numbers in TCP packet

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

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
0 Kudos
Message 1 of 10
(3,992 Views)

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

0 Kudos
Message 2 of 10
(3,987 Views)

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

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
0 Kudos
Message 3 of 10
(3,985 Views)

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

Message 4 of 10
(3,967 Views)

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!

Message Edited by Rod on 07-28-2009 12:55 PM
0 Kudos
Message 5 of 10
(3,964 Views)

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?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Kudos
Message 6 of 10
(3,945 Views)

Flatten to string has an input to specify the endianess. You could also use swap bytes or swap words.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 10
(3,942 Views)

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.

0 Kudos
Message 8 of 10
(3,916 Views)

Convert dbl to U64 then use swap words. Swap Words is polymorphic and will adapt the the data type you prest to it.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 10
(3,906 Views)

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

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 10 of 10
(3,900 Views)