我正在尝试通过 Windows7/32 位和 NI-VISA 5.4.1 下的 PyVISA 1.7 通过他们的 VICP VISA 通行证 (TCP/IP) 连接到 LeCroy Wavesurfer 400 系列:
import visa
rm = visa.ResourceManager()
scope = rm.open_resource("VICP::169.254.201.2::INSTR")
print(scope.query("*IDN?"))
我收到以下错误:
Warning (from warnings module): File "C:\Python27\lib\site-packages\pyvisa\ctwrapper\functions.py", line 1378 alias_if_exists)
VisaIOWarning: VI_WARN_EXT_FUNC_NIMPL (1073676457): The operation succeeded, but a lower level driver did not implement the extended functionality.
Traceback (most recent call last): File "C:\path\scopeTest.py", line 4, in scope = rm.open_resource("VICP::169.254.201.2::INSTR")
File "C:\Python27\lib\site-packages\pyvisa\highlevel.py", line 1614, in >open_resource info = self.resource_info(resource_name)
File "C:\Python27\lib\site-packages\pyvisa\highlevel.py", line 1584, in >resource_info
raise ValueError('Could not parse resource: %s (error code %s)' % >(resource_name, ret))
ValueError: Could not parse resource: VICP::169.254.201.2::INSTR (error code None)
在 LabVIEW 下,与此 VICP 地址下的设备的连接和通信有效。此外,当在 open_resource() 中使用 TCPIP:: 而不是 VICP:: 时,连接建立时没有警告和错误,并且 print( scope.ask("*IDN?")) 有效,但其他设备命令如 scope.write("C1:VDIV .02") 无效
print(scope.query("C1:VDIV .02"))
WARNING : CURRENT REMOTE CONTROL INTERFACE IS TCPI
得出结论,为了正确控制设备,必须使用 VICP 通行证。 当使用 PyVISA 1.5 但其他配置相同并尝试通过以下方式连接时:
scope = visa.instrument("VICP::169.254.201.2::INSTR")
给出:
Warning (from warnings module): File "C:\Python27\lib\site-packages\pyvisa-1.5-py2.7.egg\pyvisa\ctwrapper\functions.py", line 1208 alias_if_exists)
VisaIOWarning: VI_WARN_EXT_FUNC_NIMPL (1073676457): The operation succeeded, but a lower level driver did not implement the extended functionality.
Warning (from warnings module):
File "C:\Python27\lib\site-packages\pyvisa-1.5-py2.7.egg\pyvisa\highlevel.py", line 315 return Instrument(resource_name, resource_manager=self, **kwargs)UserWarning: given resource was not an INSTR but Unknown
对于 PyVISA 的早期版本,这是针对仪器的空字符串返回进行讨论的:
http://osdir.com/ml/python.pyvisa.devel/2007-07/msg00003.html
和
http://sourceforge.net/p/pyvisa/bugs/5/
我怀疑问题是 C:\Python27\lib\site-packages\pyvisa\constants.py 中的 InterfaceType 对于 VICP 连接协议(protocol)不存在在 PyVISA 中。当 resource_info() 时,抛出错误的行,在 C:\Python27\lib\site-packages\pyvisa\highlevel.py 被调用
def resource_info(self, resource_name): """Get the extended information of a particular resource :param resource_name: Unique symbolic name of a resource. :rtype: :class:`pyvisa.highlevel.ResourceInfo` """ ret, err = self.visalib.parse_resource_extended(self.session, resource_name) if err == constants.StatusCode.success: return ret raise ValueError('Could not parse resource: %s (error code %s)' %(resource_name, ret))
似乎导致与 interface_type 不匹配,或者可能是 resource_class 的问题以及与旧版本的 PyVISA 一样的返回问题?
请您参考如下方法:
显然,根据 https://github.com/hgrecco/pyvisa/issues/168,OP 最终确实解决了这个问题.在此线程中,hgrecco (Hernan Grecco) 说“我已经实现了一种强制使用资源 python 类的方法。”
那里给出的解决方案似乎对我有用:
import visa
from pyvisa.resources import MessageBasedResource
rm = visa.ResourceManager()
scope = rm.open_resource('VICP::192.168.1.109::INSTR', resource_pyclass=MessageBasedResource)
