LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Advice for data transmission from LabVIEW to C (or Python, etc)

Solved!
Go to solution

 


wrote:

I would go with a basic TCP stream. If all you are sending is an array of U16 integers than it is very straightforward. You can simply flatten it to a string and mark the "Append length" to true. The receiving side would read the length and then read length * 2 bytes of data. If you may need to have different data packets prepend a data ID to your data transmission. Clusters of basic data types flatten to string pretty nicely and map to C structs pretty closely if you need some additional data in your packets. Just remember that a LabVIEW string will end up being a 4 byte length followed by the actual characters. The C structure definition should define the string as a length and character array. You will need to determine the maximum data length and should limit the LabVIEW code to strings of the maximum length.


Just to add to what Mark has already described, please keep in mind that LabVIEW follows a Big Endian format whereas typical C based environment are usually Little Endian. This would mean that if your are sending a U16 data from LabVIEW to C by flattening it to a string, you have to swap the the bytes of your U16 data either before sending it to C based program or after it is received in the C software.

 

Please refer the following for more information.

http://www.ni.com/white-paper/3524/en/

-----------------------------------------------------------------------------------------------------------------------------
Waiting For the inner calling 🙂


0 Kudos
Message 11 of 12
(734 Views)

wrote:

 Just to add to what Mark has already described, please keep in mind that LabVIEW follows a Big Endian format whereas typical C based environment are usually Little Endian. This would mean that if your are sending a U16 data from LabVIEW to C by flattening it to a string, you have to swap the the bytes of your U16 data either before sending it to C based program or after it is received in the C software.

 

Please refer the following for more information.

http://www.ni.com/white-paper/3524/en/


Actually if you use the Flatten to String function in LabVIEW you can choose as one of the parameters which Endianess the resulting byte stream should have. So if you know you send your data to a C program that runs on a Little Endian machine, you can simply choose that and then your C program can just interpret the data directly without bothering about endianess.

While LabVIEW uses internally whatever endianess the underlying system uses (currently Little Endian on all systems but the PowerPC based cRIOs) it standardizes on Big Endian byte order for flattened data streams (historically because LabVIEW originates from 68k Macs which used Big Endian format as well as the fact that Big Endian is the standard byte order in most platform agnostic network protocols), it supports flattening to and unflattening from the other format. 

Rolf Kalbermatter
My Blog
Message 12 of 12
(724 Views)