From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
09-30-2016 10:11 AM
How do you decode, unpack a flattened string in Python which was sent by a LabVIEW TCP server?
I want to exchange data via loopback. Therefore I take a sine wave and flatten it to string and sent over the network via ServerSine.vi. Then I have to decode the incoming data in a way that I have the correct numerical values like when I plot them in LabVIEW. I did this so far in python_client.py but the values are wrong.
Does anyone know how to decode this correctly?
Solved! Go to Solution.
10-01-2016 05:06 AM
Do you want to achieve this is LabVIEW or Python.
10-01-2016 05:24 AM
I want to decode the data in python to its original values. I want to use python as a bridge between two applications. Therefore I need the correct data in python.
10-01-2016 07:52 AM
This is a LabVIEW Forum, Hopefully you will get better information if its based in LabVIEW.
Long Before i have used Python but i dont have Pythin IDE to Try your Requirement anyway try to share the data which needs to be decoded i will try to verify.
10-01-2016 09:44 AM
This is a labview question! This is why I posted it here! Labview encodes data by flattening. This is some compressed binary. The user manual just says this represents some internal structure. This is not helping. There has to be some documentation on this. Probably the developer manual on how this data is encoded. This is what I am trying to find.
10-01-2016 10:07 AM - edited 10-01-2016 10:15 AM
I guess the question is how LabVIEW stores dynamic data in memory. Unfortunately, it is not mentioned here or here. I am actually not sure, because dynamic data can contain a variety of data flavors. (Note that most seasoned LabVIEW programmers don't use express VIs or dynamic data).
Dynamic data is unique to LabVIEW, so what I would do is convert the dynamic data to something more defined, e.g. a waveform or even a simple 1D DBL array before flattening and transmitting. Now unflatten in python should be easy.
10-01-2016 10:10 AM
@maik.holzhey wrote:This is some compressed binary.
No, there is no compression involved. Flattening takes everything bit-by-bit and adds size headers if necessary.
10-03-2016 04:10 AM - edited 10-03-2016 04:23 AM
It's not like it would be impossible to find out but that would require someone to dig into it as did various people before for the more standard datatypes. However I don't think that dynamic data is a good datatype for transfering to other clients than LabVIEW. While LabVIEW defines the standarad types pretty well and also documents the memory layout of them (and by extension the flattened format which is just the memory format with additional size elements prepended for any variable sized element (arrays and strings)) this is not true for the dynamic datatypes (variant and dynamic data). NI kept these formats undocumented for several reasons, the most prominent probably that you can always go and change undocumented details, while once you document low level details you can not modify them easily anymore.
And yes I don't use dynamic data anywhere, and very seldom express VIs, but that aside, flattening dynamic data to be interpreted in another application than LabVIEW is a pretty bad idea. Waveforms are a much better format as that one is basically documented and personally I would use an explicit format for communication with non LabVIEW applciations. If performance is critical simply a cluster of a t0, deltaT and data array and otherwise something like Flattening to JSON which would make the decoding in the other application pretty trivial as you can find nowadays ready made JSON libraries for even the most exotic programming language.
10-03-2016 04:25 AM
Yes it seems that way. I am able to transfer and decode a string from a control input without Problems. Also the string length which I have has an int before flattening and sending can be decoded correctly. I will try to convert my application in way that it sents integer data before flattening. The binary decode should work then. I guess using dynamic data for this is a bad idea as I have just learned. So I hope I can correct this this week if I find the time and post an example solution. Thx
10-03-2016 10:59 AM
@maik.holzhey wrote:I will try to convert my application in way that it sents integer data before flattening.
Why integer? Floating point seems much more appropriate. (A sine function with an amplitude of 1 will only have three possible integer values (-1, 0, 1). Probably not what you want).
What else do you need to send (timing information, signal name, etc.). If all you need is a sine function, look in the "signal processing...signal generation" palette. Some output a 1D array directly.