【问题标题】:Using visa to interface with GPIB always gives me VisaIOError使用 visa 与 GPIB 接口总是给我 VisaIOError
【发布时间】:2012-05-16 09:29:42
【问题描述】:

我正在尝试在 Python 中导入 visa 并与 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后,还是不行。

有人可以帮帮我吗?

【问题讨论】:

  • 您是否尝试省略timeout 或设置timeout=None?根据pyvisa.sourceforge.net/pyvisa.html#sec-timeouts
  • @jadkik94 好吧,正如你所说,在我将timeout 更改为None 之后,系统似乎在无限循环中运行....timeout 是指最大值吗?每条指令实际允许的时间?
  • 我猜。这是文档在超时部分中所说的。我不知道,这就是为什么它只是一个评论而不是答案。
  • @jadkik94 好的,谢谢你的 cmets。

标签: python gpib visa


【解决方案1】:

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

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

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

注意:如果您使用的是可查询的命令(它是写和读的组合),您可以使用 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?')

【讨论】:

    【解决方案2】:
    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 设备。

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-12-26
        • 1970-01-01
        • 2017-12-08
        • 1970-01-01
        • 2014-04-04
        • 1970-01-01
        • 2019-10-07
        相关资源
        最近更新 更多