使用 class 访问 python 签证模块 vxi11.py 时出现问题

Problem in accessing python visa module vxi11.py using class

我正在使用名为 vxi11 的 python 仪器模块来访问通过 GPIB 连接到以太网的电压表。

如果我直接在我的主程序中使用模块vxi11,我可以访问设备,如下所示;

import vxi11
if __name__ == "__main__":


    ################# Accessing the instrument without Class ##################
    ip = "192.168.1.5"
    DVM_addr = 23
    DVM_NPLC = 60

    def Open_GPIB(ip,addr):
              #addr_str = "gpib0," + unicode(addr)
              addr_str = "gpib0," + "{}".format(addr)
              return vxi11.Instrument(ip,addr_str)

    DVM = Open_GPIB(ip,DVM_addr)
    DVM.write("END ON")
    NPLC = "NPLC " + "{}".format(DVM_NPLC)
    DVM.write(NPLC)

然而,当我尝试使用基于 class 的方法时,它会导致以下错误;

bash-4.2$ temp1.py 
Traceback (most recent call last):
  File "./temp1.py", line 49, in <module>
    dvm.write("END ON")
  File "/anaconda3/python3.7/site-packages/vxi11/vxi11.py", line 727, in write
    self.write_raw(str(message).encode(encoding))
  File "/anaconda3/python3.7/site-packages/vxi11/vxi11.py", line 635, in write_raw
    self.open()
  File "/anaconda3/python3.7/site-packages/vxi11/vxi11.py", line 601, in open
    raise Vxi11Exception(error, 'open')
vxi11.vxi11.Vxi11Exception: 3: Device not accessible [open]

以下是我基于 class 的方法的代码;

import vxi11
class bppscalib(object):

    def __init__(self):

        self.ip = "192.168.1.5"
        self.DVM_addr = 23
        self.DVM = 0

        self.DVM_NPLC = 60
        self.Cycles = 165
        self.Cycle_time = 1.0

    def Open_GPIB(self, ip, addr):

        addr_str = "gpib0" + "{}".format(addr)
        return vxi11.Instrument(ip,addr_str)

if __name__ == "__main__":

    ################## Accessing the instrument with Class ###################
    bppscalib = bppscalib()
    dvm = bppscalib.Open_GPIB(bppscalib.ip,23)
    dvm.write("END ON")
    NPLC = "NPLC " + "{}".format(bppscalib.DVM_NPLC)
    dvm.write(NPLC)

下面是 python 指向的 vxi11 中的 line 601

    def open(self):
        "Open connection to VXI-11 device"
        if self.link is not None:
            return

        if self.client is None:
            self.client = CoreClient(self.host)

        self.client.sock.settimeout(self.timeout+1)
        error, link, abort_port, max_recv_size = self.client.create_link(
            self.client_id,
            0,
            self._lock_timeout_ms,
            self.name.encode("utf-8")
        )

        if error:
            raise Vxi11Exception(error, 'open')

        self.abort_port = abort_port

        self.link = link
        self.max_recv_size = min(max_recv_size, 1024*1024)

我的猜测是我在 class 中包含 vxi11.py 模块的方式不正确,请参阅 def Open_GPIB()?

中的行 return vxi11.Instrument(ip,addr_str)

或者我可以使用 pyVisa 模块,但我不知道如何使用它,我的 GPIB 设备位于端口 23,IP 地址是 192.168.1.5。如果我要使用 pyVisa,什么相当于;

def Open_GPIB(ip,addr):
              #addr_str = "gpib0," + unicode(addr)
              addr_str = "gpib0," + "{}".format(addr)
              return vxi11.Instrument(ip,addr_str)

等同于 DVM.write("END ON")

谢谢

我明白了。 gpib0 中的 Open_GPIB() 函数中缺少一个逗号,它应该是 gpib0,

addr_str = "gpib0," + "{}".format(addr)