06-15-2024 10:16 AM
I have several labview VIs that I want to script using a text based language. In particular, I want to be able to run the VIs within python or C++, whereby I can provide the VI arguments in the code and read any data it returns. Does anyone have any experience with this, and if so could you point me in the right direction to get a starting point?
Cheers
06-15-2024 11:03 AM
By scripting, do you mean writing up a VI from scratch by defining the block diagram and front panel programmatically from a "text-lanaguage"?
06-15-2024 12:36 PM - edited 06-15-2024 12:36 PM
I guess you want to call VIs (rather than script) from python or C++.
While in interpreted languages like python, the word "script" is used interchangeably with "code", in LabVIEW, "VI Scripting" has a completely different meaning. It is a LabVIEW code that can create or edit another LabVIEW code (block diagram / front panel).
You can of course call LabVIEW VIs from external code by first compiling them to a shared library (dll).
You can also compile them to a .NET assembly.
Then import the library in your code as you would do for a "standard" C dll or .NET dll.
Regards,
Raphaël.
06-19-2024 04:49 AM
LabVIEW contains the so called VI Server. This is an Inter Application Control interface which also can be accessed from inside LabVIEW (which is by far the most easy way to use it).
There are two other interfaces, one is TCP/IP based and the other is ActiveX based.
The TCP/IP based interface is a proprietary binary communication protocol that is undocumented. The only documented way to access that is from within LabVIEW itself with its VI Server property and method nodes. One possibility is to create a LabVIEW DLL or .Net Assembly that does the necessary scripting calls and provides functions to do what you need. These functions can then be called from any other application and programming language that allows you to call DLL functions or .Net assemblies.
The ActiveX interface is a fairly small subset of the VI server protocol but would work for what you want to do. It is however legacy technology (Microsoft would love if they could make users forget that there ever was something like ActiveX). And NI has not invested anything in this interface since over 15 years. It still works but documentation about it is getting harder and harder to find as NI tries to remove most references to that, since there is factually nobody who will help you when it doesn't work. Python can call this interface with the pywin32 module and use the win32com class.
A few interesting links that may get you a bit further:
https://labviewwiki.org/wiki/ActiveX
https://rajsite.github.io/unofficial-lvdocs/lvconcepts/Using_ActiveX_with_LabVIEW.html
06-19-2024 02:07 PM
You don’t provide enough detail to show the complexity of the data being sent and received. If they can be expressed as simple strings, then the web server interface may be the quickest solution. Open the LabVIEW project and enable the web server. Any Language can send an HTML request with the VI path and any parameters and parse the response as the result.
Look for sample code in the LabVIEW examples.