06-10-2024 05:31 AM
Hi all,
Is there an easy or official way to control the LabVIEW GUI/software from Python that I might have overlooked? I came across the repository python_labview_automation, but it seems to have been inactive for about 9 years. Should I look into using LabVIEW "Shared Network Variables" ?
NI has clearly integrated Python into their ecosystem with several actively supported libraries for controlling NI devices from Python. However, my challenge is different: I have devices (not necessarily from NI) that already provide a LabVIEW interface. While I can communicate with most of them directly via SCPI, I’m looking for a way to control the LabVIEW interface to avoid having two entry points and duplicating logic (GUI vs remote automation).
I run my automated scripts and Python calls from RobotFramework, and this is a constraint that cannot be changed.
Any insights or suggestions on how to approach this would be greatly appreciated!
Thanks,
Francis
06-10-2024 09:49 AM
None is 'easy', but:
- Shared variables can work
- TCP/IP or UDP and send commands
- If the GUI isn't absolute necessary you can turn it into a DLL and call it from Python
- Same as above but .NET dll.
- write commands to a file that you monitor
06-10-2024 10:01 AM
@FrancisGohier wrote:
Hi all,
Is there an easy or official way to control the LabVIEW GUI/software from Python that I might have overlooked? I came across the repository python_labview_automation, but it seems to have been inactive for about 9 years. Should I look into using LabVIEW "Shared Network Variables" ?
NI has clearly integrated Python into their ecosystem with several actively supported libraries for controlling NI devices from Python. However, my challenge is different: I have devices (not necessarily from NI) that already provide a LabVIEW interface. While I can communicate with most of them directly via SCPI, I’m looking for a way to control the LabVIEW interface to avoid having two entry points and duplicating logic (GUI vs remote automation).
I run my automated scripts and Python calls from RobotFramework, and this is a constraint that cannot be changed.
Any insights or suggestions on how to approach this would be greatly appreciated!
Thanks,
Francis
You can make them a gRPC service and use it from Python.
06-10-2024 02:29 PM
@Yamaeda wrote:
None is 'easy', but:
- Shared variables can work
- TCP/IP or UDP and send commands
- If the GUI isn't absolute necessary you can turn it into a DLL and call it from Python
- Same as above but .NET dll.
- write commands to a file that you monitor
The .net dll can sound intimidating but it's dead easy to use in Python, C#, C++, or even directly in PowerShell.
Here's one that might do what you need. It exports one VI that connects to LabVIEW development or RTE via VI server and sets a single control value by name. It uses the JDP json library to adapt JSON to LabVIEW Variant.
The python side is pretty easy
import sys
import os
import clr
import json
path_to_dll_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'build')
sys.path.append(path_to_dll_folder)
clr.AddReference('SetValFromPython')
from SetValFromPython import *
SetValFromPython.SetVal('localhost',3365,'SetVal.vi','MachineName',json.dumps('hello world'))
Using pythonnet
06-14-2024 08:34 AM
Firstly, thanks for your answers and the extended example.
Given I would like to keep the GUI operational for use by a local user, and that I would like to remotely control the device/GUI from another machine on the network. I assume I can not use the DLL solutions.
The remaining options are:
- Network Shared variables
- TCP/IP or UDP and send commands
- write commands to a file that you monitor
- gRPC service
I would like to pick the most simpler and native one.
My understanding is that network shared variables is the most "native", but not so easiest to interact with from a Python script.
I assume that going through a file, is not as efficient as it relies on monitoring rather than listening for update.
Am I right?
Then I have to choose / try:
- TCP/IP or UDP and send commands
- gRPC service
What are the pros and cons of each method?
Do you know of any example/article on the topic?
Thanks
06-14-2024 11:07 AM
@FrancisGohier wrote:
Firstly, thanks for your answers and the extended example.
Given I would like to keep the GUI operational for use by a local user, and that I would like to remotely control the device/GUI from another machine on the network. I assume I can not use the DLL solutions.
That DLL is using VI server to actually talk to the LabVIEW program, which works over a network. In your case the DLL would exist wherever the python script is running.
https://www.ni.com/docs/en-US/bundle/labview/page/creating-a-vi-server-application.html