LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Control VI through Python script

Hello,

 

I am working on a project in which I have to launch a VI (Labview program) through my GUI wrote in python. I have not the administrator rights so I installed PyCharm Community with the JetBrain Toolbox and python 3.3 with a msi file.

I read on internet that to do what I want, I need to install the pywin32 extension (https://sourceforge.net/projects/pywin32/files/?source=navbar) but when I launch it, it doesn't find my python installation.

 

So, my question is : is there another way to control VI from python ?

 

Thank in advance for your answer. I am a beginner in both language.

Mathieu Gauquelin
0 Kudos
Message 1 of 3
(4,242 Views)

Bon jour, Mathieu.

 

     I don't have a direct answer to your question.  I played enough with Python to know I don't like it and don't see a use for it in the things that I'm doing, but I am pretty familiar with LabVIEW, so I'll try to bring up so points for you to consider (as you are learning both of these systems).

 

     LabVIEW (the Program) is a Development System for LabVIEW Virtual Instruments (VIs), a graphical representation of code that gets compiled and executed in the Development System.  In addition to running VIs from within the LabVIEW Development System, you can also build stand-along Executables that work with libraries supplied by National Instruments.

 

     So the first question is are you envisioning Python interacting with an Executable developed in LabVIEW, or with VIs running in the LabVIEW Development System?  In any case, an issue would be how Python would get information in and out of the LabVIEW code.  You could set up TCP/IP communication between the Python and the LabVIEW routines, but now it starts getting complicated.

 

     On the other hand, there are LabVIEW "hooks" into Python (I have no experience using them, but I know they are out there).  If you made the LabVIEW code the "Master", you can probably call Python routines to do whatever you needed Python to do.

 

     I'm sure other LabVIEW Users with more experience with Python than I will also reply, so don't be too discouraged by my response ...

 

Bob Schor

0 Kudos
Message 2 of 3
(4,192 Views)

Hello,

Thanks for your answer. Indeed before to read your answer I succeeded to put in place a TCPIP communication between Python and LabVIEW. Python is the server and the VI the client. In this way I am able to discuss both ways and it is the first part I wanted, that is to say get data from LabVIEW. But this solution needs to launch the Python code and after run the VI and it is not very cool for the future user of my program I think.

It is why I try to launch the VI through Python. My Labview program is just a while loop which send data and receive from my python program. I finally find a workaround to install the library needed (win32com) for Python. Then, I succeeded to launch a VI and set some values through Python.

Though, I try now to do the 2 solutions in the same time, the first one (TCPIP) to exchange data and the second one to launch the LabVIEW program (because I don't now again if I can send array with an ActiveX object). It seems to be quite hard.

For information, to launch a VI with Python, I do :

import win32com.client
LabVIEW = win32com.client.Dispatch("Labview.Application")
VI = LabVIEW.getvireference('C:\\MG\\Labview Python\\python.vi')
VI._FlagAsMethod("Call")
VI.Call()

Finally, I am working with VI running in the LabVIEW Development System but I think in few weeks it will be with executable.

I will continue to investigate why it is not working but if you have some clues, don't hesitate to discuss about it or send me a private message.

Best regards.

Mathieu Gauquelin
Message 3 of 3
(4,180 Views)