LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Python and LabVIEW

Has anyone connected Python and LabVIEW?

I would like to use Python as a scripting language with LabVIEW for the task
that may be done simplier in Python.

I have some ideas about connecting via TCP/IP. But may be someone has
already done this?

Regards,
---Dmitry.
0 Kudos
Message 1 of 5
(5,596 Views)
I have called Python scripts from LabVIEW using system exec. The attached VI has the ability to pass arguments. Data is returned from Python as print statements and then parsed.

-Jim
Message 2 of 5
(5,596 Views)
I've never used Python with LabVIEW before, but I know that LabVIEW can call functions from DLLs or shared libraries. You could write a little DLL that wraps a Python interpreter (i.e. has a Python interpreter embedded in it) and provides a function that LabVIEW can call to execute a script.

Another option is to just call the necessary functions (e.g. Py_Initialize(), PyRun_SimpleString()) directly from the Python DLL from LabVIEW.

I think either of these two options would be easier than using TCP/IP since you won't have to invent a protocol.

You can find more information about embedding Python here: http://www.python.org/doc/current/ext/embedding.html

-Anthony
Message 3 of 5
(5,596 Views)
This is a followup to my previous answer:

Just to see if it would work, I went ahead and implemented solution #2: call the Python DLL functions from LabVIEW. I used the "Call Library Function" VI to do this. Unfortunately my VI will only work on Windows with Python 2.0 because under other OSs or other Python versions the DLL will have a different name, but it is a trivial task to change the DLL name in the VIs. This solution should work on any platform that has Python and LabVIEW.
0 Kudos
Message 4 of 5
(5,596 Views)
Ack! Disregard the previous VI, it is somewhat broken. I've attached a new one to this comment that works much better. The previous VI wouldn't let you use any Python builtin functions.

Note: in order for LabVIEW to get the result of the executed the Python code, the result must be stored in a global variable named 'result'. The VI always interprets the result as a string, but it would be trivial to make it interpret it as a number instead (i.e. replace PyObject_Str() and PyString_AsString() with PyInt_AsLong())
0 Kudos
Message 5 of 5
(5,596 Views)