ni / python_labview_automation

MIT License
167 stars 59 forks source link

TCP Connection will auto close #3

Open tosobright opened 5 years ago

tosobright commented 5 years ago

Python Code: from labview_automation import LabVIEW

vi_path = 'C:\Users\Administrator\Desktop\add.vi' lv = LabVIEW() lv.start() # Launches the active LabVIEW with the listener VI with lv.client() as c: control_values = { "a": 2, "b": 5 } indicators = c.run_vi_synchronous( vi_path, control_values) print(indicators['c'])

error_message = c.describe_error(indicators['Error Out'])

lv.kill() # Stop LabVIEW

LVAutomation Listener: [2019/3/29 9:17:52] (GUID - 5c9cad606465322594000008) Command received.

Message: { "run_options" : 0, "indicator_names" : [], "control_values" : { "a" : 2, "b" : 5 }, "vi_path" : "C:\Users\Administrator\Desktop\add.vi", "command" : "run_vi", "open_frontpanel" : false } [2019/3/29 9:17:52] (GUID - 5c9cad606465322594000008) Command sent successfully.

Message: { "c" : 7.0000000000, "RunVIState_Status" : false, "RunVIState_Code" : 0, "RunVIState_Source" : "" } [2019/3/29 9:17:52] (TCP Connection-5c9cad606465322594000008) Lost

Python Shell:

lv.client().run_vi_synchronous(vi_path, control_values)

Traceback (most recent call last): File "<pyshell#0>", line 1, in lv.client().run_vi_synchronous(vi_path, control_values) File "D:\Python\Python27\lib\site-packages\labview_automation\labview.py", line 175, in client raise NotStartedError("You must start LabVIEW to get talk to it.") NotStartedError: You must start LabVIEW to get talk to it.

alexbhandari commented 4 years ago

I was having this issue as well. By specifying 32bit with lv=LabVIEW(bitness='x86') I was able to keep the connection open long enough to run my VI. Does this work for you? It still does seem to auto close after code completes for me. Also you may need to be running both 32 bit labview and python for this to work smoothly. That's just a guess though since there doesn't seem to be much documentation on this that I can find.

alexbhandari commented 4 years ago

Did some more testing and I still have this issue actually, but only on the first run. When I run for the first time and the listener opens then it will close before running the command and throw this error. However, if I then run my script a second time leaving the listener window open from the first run, then it will run the command successfully.