Guillaume Lessard Posted July 7, 2007 Report Share Posted July 7, 2007 Hi, I'm working on a little messaging framework to send data over TCP between two machines. That's simple enough, and I thought I'd save myself a bit of work when sending complex data types by converting them to variants and then flattening the variants to strings. What I didn't realize is that "Variant to Flattened String" doesn't really flatten into a string, but into a string and an array of integers. That doesn't really help for sending data over TCP, unless I cluster that up, flatten the cluster and send that. Ick. Is it necessary to use "Variant to Flattened String"? My cursory testing indicates that "Flatten to String" works fine for variants; I haven't found a case where it fails. Note that I'm not interested in using any of the fancy features of variants in this case. The online help and examples do not bother to go into the whys and wherefores, and so are unhelpful for this! Thanks for illuminating me, Quote Link to comment
jpdrolet Posted July 7, 2007 Report Share Posted July 7, 2007 Variant to Flattened String and Flatten to String both act exactly the same when used on typed data. When used with a variant input, Variant to Flattened String returns the flattened string of the data contained in the variant, same as is contained data was input to Flatten to String When used with a variant input, Flatten to String returns the flatttened data of the variant, e.g. the flattened data of the contained typed data plus the flattened type descriptor of the the typed data. When you send that thru TCP, the variant is exactly reconstructed with its contained typed data so it is safe to use. Quote Link to comment
Guillaume Lessard Posted July 7, 2007 Author Report Share Posted July 7, 2007 Thanks for the info, JP. Quote Link to comment
gb119 Posted July 7, 2007 Report Share Posted July 7, 2007 QUOTE(Guillaume Lessard @ Jul 5 2007, 11:45 PM) Hi,I'm working on a little messaging framework to send data over TCP between two machines. That's simple enough, and I thought I'd save myself a bit of work when sending complex data types by converting them to variants and then flattening the variants to strings. What I didn't realize is that "Variant to Flattened String" doesn't really flatten into a string, but into a string and an array of integers. That doesn't really help for sending data over TCP, unless I cluster that up, flatten the cluster and send that. Ick. [...] Assuming you don't care too much how verbose your TCP transmissions are, why not use the (un)flatten to/from XML functions ? They (obviously) don't use a type descriptor array and with the string data being human readable it might be easier to debug if the conversion failed... Quote Link to comment
Ton Plomp Posted July 10, 2007 Report Share Posted July 10, 2007 One thing to add, make sure the '(Un) flatten to/from string' functions are in the same LabVIEW version. Variants have been known to change from version to version, most of the time a compatibility mode is available (see in 8.x the 'Unflatten from string' right click) Ton Quote Link to comment
Sparc Posted July 11, 2007 Report Share Posted July 11, 2007 QUOTE(Gavin Burnell @ Jul 6 2007, 02:35 PM) Assuming you don't care too much how verbose your TCP transmissions are, why not use the (un)flatten to/from XML functions ? They (obviously) don't use a type descriptor array and with the string data being human readable it might be easier to debug if the conversion failed... These functions are substantially slower than the raw Flatten/Unflatten. Fine for a final write out to file, but not something I'd want in a loop. Sparc Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.