LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send class data over TCP/IP like a serialized cluster

I have a device which communicates over a TCP/IP connection.  I need to construct complex messages for the communications.  If I use type-defs clusters it is a simple matter to convert the data to string and send it out.  Same with getting the data in.

 

If I try this with classes (which I really want to use instead of type-def clusters) I don't get my data in the same format I want it to be in.  It gives me a bunch of stuff I don't want or need like the name of the class.

 

I can do some crazy shenanigans like below but this will break if my data type ever changes.

 

In addition to that problem some of my classes will contain other classes as data members.  For example all messages have a message header as their beginning so a separate message header class will be part of all other classes.

 

Is there a built in / simple way to do this?

 

Thanks for the help,

James G. 

 

0 Kudos
Message 1 of 5
(4,334 Views)

Did you try flatten to xml string instead of flatten to string? I think that flatten to string is not network safe because it uses the high order bit. You can only safely send ASCII which is the lower seven bits.

=====================
LabVIEW 2012


0 Kudos
Message 2 of 5
(4,329 Views)

The recieving device will have no idea how to handle all the added tags that xml puts in the string.  What I am looking for is just the data.  Like what you would see if you looked at a struct in memory.

 

I am a bit new to the labview classes so I'm not even sure if this is possible with.  I just may be forced to roll my own.  (I really hope not).

0 Kudos
Message 3 of 5
(4,325 Views)

Got it. I thought the receiving device was running LabVIEW Smiley Happy You could write a method for your class to return the data in whatever format you want.

=====================
LabVIEW 2012


0 Kudos
Message 4 of 5
(4,315 Views)

You could put a typedef'd cluster inside the class private data, which would make it easy to flatten at the cost of an extra layer of clustering (not a big deal).  If the class contains other classes, put them only in the class data, not in the typedef.  Each class should have a Flatten method and you can then concatenate the strings together.

Message 5 of 5
(4,301 Views)