LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling LabVIEW GUI from Python - Any Easy/Official Way

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

0 Kudos
Message 1 of 6
(312 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 6
(258 Views)

@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.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 3 of 6
(249 Views)

@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.

avogadro5_0-1718047406732.png

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

Message 4 of 6
(215 Views)

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
 

0 Kudos
Message 5 of 6
(142 Views)

@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

Message 6 of 6
(123 Views)