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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Python client to unflatten received string from TCP Labview server

Solved!
Go to solution

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?

Download All
0 Kudos
Message 1 of 35
(5,652 Views)

Do you want to achieve this is LabVIEW or Python.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 2 of 35
(5,603 Views)

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.

0 Kudos
Message 3 of 35
(5,598 Views)

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.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 4 of 35
(5,589 Views)

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.

0 Kudos
Message 5 of 35
(5,583 Views)

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.

0 Kudos
Message 6 of 35
(5,579 Views)

@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.

0 Kudos
Message 7 of 35
(5,578 Views)

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.

Rolf Kalbermatter
My Blog
Message 8 of 35
(5,539 Views)

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

0 Kudos
Message 9 of 35
(5,534 Views)

@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.

0 Kudos
Message 10 of 35
(5,510 Views)