LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C struct to LabView bundle via socket

Hello

I have a C program that sends a data structure
struct {
double temp;
double coeff_heat_transfer;
int id;
}

and I send this to a labView VI using TCP/IP sockets.

Is there a way to read, from the socket in LabView
(read vi), and deposit the data directly into a bundle with
the data types named the same as the corresponding C structure?

Can someone advise?

Thanks,
Jacob
0 Kudos
Message 1 of 2
(2,872 Views)
Jacob wrote:

> Hello
>
> I have a C program that sends a data structure
> struct {
> double temp;
> double coeff_heat_transfer;
> int id;
> }
>
> and I send this to a labView VI using TCP/IP sockets.
>
> Is there a way to read, from the socket in LabView
> (read vi), and deposit the data directly into a bundle with
> the data types named the same as the corresponding C structure?

Create a cluster with two double precision numbers and one int32
integer. Use TCP Read function to read 20 bytes. Use the Advanced->Data
Manipulation->Type Cast function to convert the returned string to the
cluster. Now depending on the other side of the TCP/IP communication you
may have to wire the cluster through Swap
Bytes and Swap Words before
looking at the values.
Basically LabVIEW uses Big Endian bytestream format. So if your C
application uses that as well, either explicitedly transmitting Netwerk
Byteorder or just being simply programmed on a non x86 computer you are
ok. If the C application is written for x86 and the programmer hasn't
taken any measures to make sure all numbers are sent in Network Byte
order, you need both Swap functions to make the data look correct in
LabVIEW.

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