我正试图在x86_64 Linux机器(centos 7)上通过python控制keithley 2410。我使用的是python 2.7.5、ni-visa 16和pyvisa 1.8。Keithley通过RS232到USB电缆连接到计算机,并配置为RS232通信(参数:波特57600,位8,奇偶校验无,终端,流控制无)。当我试图查询keithley时,我得到一个超时错误,如下所示:
>>> import visa
>>> rm = visa.ResourceManager()
>>> print(rm.list_resources())
(u'ASRL1::INSTR', u'ASRL2::INSTR')
>>> keithley = rm.open_resource("ASRL2::INSTR")
>>> print(keithley.query('*IDN?'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/pyvisa/resources/messagebased.py", line 407, in query
return self.read()
File "/usr/lib/python2.7/site-packages/pyvisa/resources/messagebased.py", line 332, in read
message = self.read_raw().decode(enco)
File "/usr/lib/python2.7/site-packages/pyvisa/resources/messagebased.py", line 306, in read_raw
chunk, status = self.visalib.read(self.session, size)
File "/usr/lib/python2.7/site-packages/pyvisa/ctwrapper/functions.py", line 1582, in read
ret = library.viRead(session, buffer, count, byref(return_count))
File "/usr/lib/python2.7/site-packages/pyvisa/ctwrapper/highlevel.py", line 188, in _return_handler
raise errors.VisaIOError(ret_value)
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
最佳答案
PYVISA 1.8应默认为串行的“\r”行终止,因此您的2410可能没有收到需要启动它来解析命令的“\n”。Try doing
keithley.write_termination = '\n'
keithley.read_termination = '\n'
就在你的电话之后。