2

我正在尝试visa在 Python 中导入并与之交互GPIB以控制设备。我使用的设备名称是"GPIB0::9::INSTR",我认为这应该没有问题。

我在 2.7.3 Python Shell 中运行了以下代码

>>> from visa import *
>>> a = instrument("GPIB0::9", timeout = 20)
>>> a.write("*IDN?")
>>> print a.read()

Traceback (most recent call last):
  File "<pyshell#53>", line 1, in <module>
    print a.read()
  File "C:\Python27\lib\site-packages\pyvisa\visa.py", line 433, in read
    return self._strip_term_chars(self.read_raw())
  File "C:\Python27\lib\site-packages\pyvisa\visa.py", line 407, in read_raw
    chunk = vpp43.read(self.vi, self.chunk_size)
  File "C:\Python27\lib\site-packages\pyvisa\vpp43.py", line 840, in read
    visa_library().viRead(vi, buffer, count, byref(return_count))
  File "C:\Python27\lib\site-packages\pyvisa\vpp43.py", line 398, in check_status
    raise visa_exceptions.VisaIOError, status
VisaIOError: VI_ERROR_TMO: Timeout expired before operation completed.

以上是系统给我的错误。实际上一开始,我设置Timeout为3,它显示了这个错误。但是我如上图将值改为20后,还是不行。

有人可以帮助我吗?

4

3 回答 3

0

有不同的问题可能导致超时。首先,您应该检查您的设备是否支持该*IDN?查询。它是一个 IEEE-488.2 标准命令,因此支持它的可能性很高(如果不检查您的手册以获取支持的命令)。

然后你应该检查你的通信设置,特别是终止字符和 EOI。

如果您使用了错误的终止字符,签证将继续阅读并最终超时。

注意:如果您使用可查询的命令(它是一个组合的写入和读取),您可以使用 pyvisa 的 ask 功能。

import visa

# If you've got just one gpib card installed, you can ommit the 0.
# ASsuming the EOI line should be asserted and a termination character
# of '\n'
instrument = visa.instrument('GPIB::9', term_chars='\n', send_end=True)
# use ask to write the command and read back the response
print instrument.ask('*IDN?')
于 2013-03-18T10:04:43.307 回答
0
import visa

rm = visa.ResourceManager()
devices = rm.list_resources()
comm_channel = rm.open_resource(devices[0])     #assuming you only have 1 address to worry about

print(comm_channel.query("*IDN?"))

这利用了 PYVisa 的模块和它提供的许多功能,用于连接/写入/读取 USB/GPIB 设备。

于 2015-12-04T22:38:44.983 回答
-1

对于每一个特定的仪器,它都有自己的命令来控制它们。请参阅设备的用户手册。

于 2012-07-10T01:45:57.733 回答