python - pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): 操作完成前超时
问题描述
我正在使用 Python3 进行一些自动化工作来控制 Keysight 仪器,例如 UXA(频谱分析仪)和开关控制器(Keysight 11713C)
我的代码可以运行一段时间,但我经常在几分钟后看到签证超时错误。例如,我通过循环中的一些开关活动捕获了 100 个不同频率的频谱,它可能会运行 20 - 50 个循环,并开始显示签证超时错误。
有些文章说我需要关闭资源管理器才能让事情运行得更顺畅,所以我添加了一些额外的代码来在检测到签证超时错误时关闭资源管理器,但是这个“关闭资源管理器”活动在超时时也会失败发生。
以下是我的代码的简化版本的示例:
rm = visa.ResourceManager();
sa_inst = rm.open_resource('TCPIP0::10.10.10.1::hislip0::INSTR',write_termination= '\n', read_termination='\n')
sa = SA(sa_inst)
switch_controller_inst = rm.open_resource('TCPIP0::10.10.10.5::INSTR',write_termination= '\n', read_termination='\n')
Switch_Control = SwitchControl(switch_controller_inst)
counter = 100
if counter >0:
try:
Switch_Control.TurnOnSwitch(switch_controller_inst, switch_H1_H2)
sa_inst.write('CALC:MARK:MAX;X?;Y?')
counter = counter - 1
except visa.VisaIOError as e:
rm.close()
time.sleep(2)
rm = visa.ResourceManager();
sa_inst = >rm.open_resource('TCPIP0::10.10.10.1::hislip0::INSTR',write_termination='\n',read_termination='\n')
sa = SA(sa_inst)
switch_controller_inst = rm.open_resource('TCPIP0::10.10.10.5::INSTR',write_termination='\n',read_termination='\n')
Switch_Control = SwitchControl(switch_controller_inst)
非常令人沮丧的是,这个错误是随机发生的,并且不是每次都出现。任何帮助将不胜感激,例如作为解决方法或任何调试方法的任何技巧?</p>
以下是错误消息的示例:
Traceback (most recent call last):
File "C:/1_Python_Automation/mycode/test.py", line 594, in <module>
Switch_Control.TurnOnSwitch(switch_controller_inst, switch_H1_H2)
File "C:\1_Python_Automation\mycode\Instrument_Automation\Power_Supplies\SwitchController11713C.py", line 39, in TurnOnSwitch
inst.write(":ROUTe:CLOSe (@" + str(switch_port) +")");
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\resources\messagebased.py", line 197, in write
count = self.write_raw(message.encode(enco))
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\resources\messagebased.py", line 157, in write_raw
return self.visalib.write(self.session, message)[0]
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\ctwrapper\functions.py", line 2796, in write
ret = library.viWrite(session, data, len(data), byref(return_count))
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\ctwrapper\highlevel.py", line 222, in _return_handler
return self.handle_return_value(session, ret_value) # type: ignore
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\highlevel.py", line 251, in handle_return_value
raise errors.VisaIOError(rv)
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/1_Python_Automation/mycode/test.py", line 698, in <module>
rm.close()
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\highlevel.py", line 3096, in close
resource.close()
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\resources\resource.py", line 334, in close
self.visalib.close(self.session)
File "C:\Users\bNB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\ctwrapper\functions.py", line 637, in close
return library.viClose(session)
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\ctwrapper\highlevel.py", line 222, in _return_handler
return self.handle_return_value(session, ret_value) # type: ignore
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\highlevel.py", line 251, in handle_return_value
raise errors.VisaIOError(rv)
pyvisa.errors.VisaIOError: VI_ERROR_CLOSING_FAILED (-1073807338): The VISA driver failed to properly close the session or object reference. This might be due to an error freeing internal or OS resources, a failed network connection, or a lower-level driver or OS error.
Exception ignored in: <function Resource.__del__ at 0x00000263BC9AF550>
Traceback (most recent call last):
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\resources\resource.py", line 199, in __del__
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\resources\resource.py", line 333, in close
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\resources\resource.py", line 327, in before_close
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\resources\resource.py", line 345, in __switch_events_off
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\resources\resource.py", line 495, in disable_event
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\ctwrapper\functions.py", line 662, in disable_event
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\ctwrapper\highlevel.py", line 222, in _return_handler
File "C:\Users\NB\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa\highlevel.py", line 251, in handle_return_value
pyvisa.errors.VisaIOError: VI_ERROR_INV_OBJECT (-1073807346): The given session or object reference is invalid.
解决方案
推荐阅读
- swift - 用于 macOS Swift AppKit 应用程序的类似 Dock 行为的 API
- python-3.x - 如何在 django-import-export 中使用 ForeignKeywidget 解决 MultipleObjectsReturned
- express - 如何仅针对某些类型的文件在 webpack 上启用实时重新加载
- java - JACoCo/surefire-plugin 找不到要运行的测试
- opencv - 指纹图像增强的 Gabor 滤波器参数?
- python - 尝试使用 tkinter 使对象跳转
- r - 如何通过与上一年匹配来添加列?
- prometheus - 将自定义标签注入 Java 客户端的默认 jmx Prometheus 指标
- django - Django Query如何对返回的对象求和
- sqlite - 创建连接时如何在电容器社区/sqlite中使用newsecret