Note that standard datatypes such as unsigned or signed numerics, strings, booleans are automatically translated by the Python node.
If using LabVIEW Arrays and Python Lists:
The Python Node will automatically translate any LabVIEW Array of a supported Python datatype into a Python List of that datatype, when given the correct datatype as an input.
The following Python code:
TestList = [True, True, False]
def return_list():
x = TestList
return x
will return an array of Booleans in LabVIEW:
If using LabVIEW Clusters and Python Tuples:
The Python Node will translate Clusters or Tuples of supported datatypes.
The following Python code in conjunction with the above definition of TestList:
TestTuple = (3, 5, "TestList")
def return_tuple():
x = [TestTuple, TestTuple]
return x
will return the following LabVIEW cluster when given the correct datatype:
This will also work with named tuples.
If working with Python Dictionaries and LabVIEW clusters with named pairs:
There is no native translation for a Python Dictionary item, which are stored in key:value pairs.
Instead, a JSON string should be used for this communication. The following Python code:
import json
TestDict = {
"String": "Test",
"Number": 2,
"Other number": 3
}
def return_dict():
x = json.dumps(TestDict)
return x
can be read through LabVIEW as follows:
The naming of the variables inside the LabVIEW cluster is important.