08-25-2020 09:28 AM
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?
08-26-2020 04:20 PM
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
03-10-2021 12:59 AM
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!
03-10-2021 02:36 AM
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.