LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Launching a Vi in background, from a script

Hi,

I have a Python script that (apart from a bunch of other stuff) opens and starts a Labview Vi in WIn XP, filling in its fields via COM interface (win32com.client library).
When the scripts launches the Vi, execution control is passed to that one, and the script pauses, until the Vi stops.

What I would like to obtain is the following:
1) The script runs the Vi
2) Vi starts, goes in background, and execution resumes on the script
3) I do other stuff on the script, like acting on the running Vi buttons.

I tried setting the "Wait until done" method on the Vi, but I guess I am not doing it correctly.
Can anybody tell me how to do it?
I would like to avoid multithreading programming and I guess it is not really necessary here.
I paste below some lines of my python script.

Ciao and thanks in advance, Leodp


import win32com.client
labview = win32com.client.Dispatch("Labview.Application")
VI = labview.getvireference(r"\\Path_to\my.vi")
VI.OpenFrontPanel
# does not work VI.WaitUntilDone
VI.Run
# script should continue, with my.vi still running
VI.SetControlValue('Tab Control',0)
VI.SetControlValue('last row to read in xls',126)
# and so on
0 Kudos
Message 1 of 5
(3,229 Views)
Darn timeouts with the website threw out my response. Smiley Mad Let's try again.

This is by design. LabVIEW is waiting for the VI to finish, and Python is waiting for LabVIEW. I can offer 2 suggestions:
  1. Build your VI into an application. Not sure if this will work with Python in terms of getting control right back.
  2. Create a wrapper VI that calls your VI and launches it dynamically. This wrapper VI would return right away, giving control back to Python, while your VI is running in the background. Your Python script would call this wrapper VI. If you don't have a way to stop your VI from its front panel you would need another wrapper to be able to stop it from Python.
0 Kudos
Message 2 of 5
(3,208 Views)
Hi smercurio,

thanks, I think I will go with your suggestion 2.
But oh, how I miss the & of bash.

CIao, Leodp
0 Kudos
Message 3 of 5
(3,205 Views)
I attach a snapshot of the wrapper vi block diagram in case somebody else finds this thread.

Ciao, Leodp
0 Kudos
Message 4 of 5
(3,179 Views)
A new snapshot.
The previous version works ok if launched from within labview, but if I call it from a script I get an error (n.1000 )
The "error out" catches it and avoids the popup message.

If you need to check whether the Vi called by this wrapper is still running, you can use the ExecState. First open the reference:
labview = win32com.client.Dispatch("Labview.Application")
VI = labview.getvireference(My_vi_path)
VI.OpenFrontPanel

and then, for example:
while VI.ExecState==2:
                    time.sleep(1) # just lose some tine

Value '2' is a running Vi, value '1' is an open front panel, but stopped.

Ciao, Leodp
0 Kudos
Message 5 of 5
(3,138 Views)