LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Possible to pass objects between LV and other languages?

Is it possible to pass objects, say via JSON, into Labview and vice versa? Now I realize there's likely not a way to enforce or be aware of class heirarchy and such between two languages, and that probably one would have to ensure the class/objects are equivalent on both sides of the "language barrier" -  but is it possible if one setup an identical structure in another language, that an object, in JSON, could be instantiated in labview at runtime?

0 Kudos
Message 1 of 7
(2,896 Views)

Hi DrAutomatic,

 

what is your use case for exchanging objects between different executables?

Would it be easier (and maybe more senseful) to exchange just data?

 


@DoctorAutomatic wrote:

one would have to ensure the class/objects are equivalent on both sides of the "language barrier" -  but is it possible if one setup an identical structure in another language, that an object, in JSON, could be instantiated in labview at runtime?


Do you really think you can setup the very same internal structure used to store objects in LabVIEW with a different programming environment?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(2,855 Views)

You can Flatten to JSON\XML. And you can send it. Whether the other side can use it, isn't really a LabVIEW question, but most languages can parse XML\JSON or at least strings.

 

Note that Flatten to JSON\XML is tricky. There is a 'feature', that removes all objects of a cluster\class from the JSON\XML if\when the cluster\class is default. So in stead of sending a string with data of the object's values, you get crap.

 

You need to handle that in either LV or the other side.

 


@DoctorAutomatic wrote:

is it possible if one setup an identical structure in another language, that an object, in JSON, could be instantiated in labview at runtime?


So that's a yes, I guess.

 

Python for instance will gladly receive a JSON string, and convert it to an object. It doesn't really care about it's content...

0 Kudos
Message 3 of 7
(2,843 Views)

wiebe@CARYA wrote:

 

Python for instance will gladly receive a JSON string, and convert it to an object. It doesn't really care about it's content...


But it can't do much with such an object! The contents is just a binary stream that has no functional meaning to Python.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 7
(2,810 Views)

@rolfk wrote:

wiebe@CARYA wrote:

 

Python for instance will gladly receive a JSON string, and convert it to an object. It doesn't really care about it's content...


But it can't do much with such an object! The contents is just a binary stream that has no functional meaning to Python.


A JSON string or XML string isn't binary?

 

I got JSON strings from REST, and Python can work with it just fine.

 

Obviously a Flattened to JSON LV class it's not a class object in Python, until you set the data to the Python class. But there's no reason you can't make that work.

0 Kudos
Message 5 of 7
(2,804 Views)

Well if you don't convert the JSON then yes, it is a string basically. But you still can't do to much with it. A string object in Python has a number of specific methods and properties and that's mostly it. To convert it into a Python object with similar functionality as the LabVIEW object you would need to reprogram the object in Python and add a Serialize/Deserialize method from a LabVIEW JSON String. Very possible but also very cumbersome especially if you want to do more than one or two object classes.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 7
(2,796 Views)

@rolfk wrote:

Well if you don't convert the JSON then yes, it is a string basically. But you still can't do to much with it. A string object in Python has a number of specific methods and properties and that's mostly it. To convert it into a Python object with similar functionality as the LabVIEW object you would need to reprogram the object in Python and add a Serialize/Deserialize method from a LabVIEW JSON String. Very possible but also very cumbersome especially if you want to do more than one or two object classes.


The de-serializing of JSON in Python is easy. But that converts the JSON to a Python object.

 

Passing an object (data and functionality) is simply not possible. Passing data is very well possible.

 

I agree, converting the LabVIEW object to a Python object with the same functionality will only be practical for a few objects.

 

Not sure what OP wants with the 'objects'? 

 

>Possible to pass objects between LV and other languages?

Possible, sure. Practical, maybe.

0 Kudos
Message 7 of 7
(2,781 Views)