LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running and Aborting a labview VI using python

Hi there. I am attempting to control a labview VI using python. My VI involves a while loop that I would like to abort after some elapsed time. Currently my python code is set up similar to the following.

 

import win32com.client

LabVIEW = win32com.client.Dispatch("Labview.Application")
VI = LabVIEW.getvireference('C:\\path to vi.vi')
VI._FlagAsMethod('Call')
VI.Call()

** Some logic needed here to stop loop **

result = VI.getcontrolvalue('Array 2')
print(result)

  Because of the loop within my VI, the program hangs at VI.Call(), and I would like to be able to abort the loop after a certain amout of time has passed. Any suggestions?

0 Kudos
Message 1 of 4
(2,708 Views)

You can use an INI file which can be accessed from both the LabVIEW VI and the python code.  In that INI you have a key CONTINUE=0/1 that is written to by the python code, The LabVIEW code checks the value of that key periodically to decide if it should continue running or stop.  Once the VI stops, the python script VI.Call() should return and your script can continue.  There are lots of other schemes possible, but this one is pretty simple.

 

Hope that helps,

Craig

0 Kudos
Message 2 of 4
(2,641 Views)

Hello,

 

This solution provided sounds elegant but I am not sure how to implement it from python side  (i.e. generate this INI file and also add it in the VI while loop to check for this INI file condition).

Any suggestions or examples would he appreciated! 

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

Simplifying further, you can use any file, either a binary or a text one. Simply write your code value into the file from Python and read it from LabVIEW.

 


@HER!!  ha scritto:

 

This solution provided sounds elegant


Actually, it's a quick-and-dirty solution, not very elegant indeed. But don't get me wrong, I used it in the past: it's simple and works.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 4 of 4
(2,427 Views)