Connect to a LabVIEW VI and Executable Using Python

Updated Jun 28, 2024

Environment

Software

  • LabVIEW

I would like to connect to a running VI or executable built from a VI and control or get Front Panel values using Python.
 

This can be achieved with ActiveX methods and properties. In order to connect to your executable, you must Enable ActiveX server on the Advanced Page (Application Properties Dialog Box) under Build Specifications. You may also need to enable VI server settings for your project before creating your executable.

To do so you can utilize the win32com and pywin32 modules in your Python code. The following code connects to a running VI specified by a path and returns the value of a control called "main".

import win32com.client

labview = win32com.client.Dispatch("Labview.Application")
VI = labview.getvireference(r'c:\TEMP\ctrl\ctrl.vi')
print(f'Name: {VI.Name}')
print(VI.getcontrolvalue('main'))

If you would like to connect to a built executable you have to modify the dispatch application parameter and also the path of the VI will be added as an extra layer to the reference path:
import win32com.client

labview = win32com.client.Dispatch("ctrl.Application")
VI = labview.getvireference(r'c:\TEMP\ctrl\Ctrl.exe\ctrl.vi')

print(f'Name: {VI.Name}')
print(VI.getcontrolvalue('main'))
 
Additional Information
If your LabVIEW code includes user interface events, consider switching to custom events as the first ones won't be triggered programmatically

Was this information helpful?

Yes

No