Example Code

Controlling a VI using Python using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Overview
This is example code that takes two inputs in LabVIEW and adds them together. The VI is then called and controlled using Python.


Description
The LabVIEW code is called in Python and the front panel is controlled using ActiveX calls from Python. The output is then displayed using Python code. This code uses VI Methods and the VI Server with ActiveX enabled to control a LabVIEW VI from Python.

 

  1. Install an ActiveX Client Module for Python
  2. Enable ActiveX on the VI Server
  3. Run Python script


Requirements

Software:

LabVIEW 2012(or compatible)

 

Steps to Implement or Execute Code

  1. Download the .zip file
  2. Set your desired configuration (a, x1, x2, degrees, etc)
  3. Run the VI

 

Additional Information or References
VI Block Diagram

1.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**
Matt P.
Applications Engineer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
jseale
Member
Member
on

Great example!  Here's a question.  Lets say the main VI opens a SubVi.  Is there a way using ActiveX that I can connect to the running SubVi and then call "setcontrolvalue" on some of the controls in the SubVi?

Thanks

Nemo81
Member
Member
on

Hi jseale,

 

Did you discover out, how to control the subVi, I tried to connect to the new subVi, then send SetValue, but didnt work 😞

nilearner_lv
Member
Member
on

Hello - thank you so much for posting this example! What are the benefits/trade-offs with the posted approach vs. (https://github.com/ni/python_labview_automation) developed by a NI engineer. Essentially, it allows you to interface with LabView control values and indicators.

 

I would like to know so I can consider which best meets the needs of a project that I am working on.

 

Thank you!

 

Winston