首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用类访问python visa模块vxi11.py的问题

使用类访问python visa模块vxi11.py的问题
EN

Stack Overflow用户
提问于 2019-12-09 19:23:37
回答 1查看 453关注 0票数 0

我正在使用称为vxi11的python测试模块来访问一个通过GPIB连接到以太网的伏特表。

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

代码语言:javascript
复制
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)

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

代码语言:javascript
复制
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]

以下是基于我的课堂教学方法的代码;

代码语言:javascript
复制
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所指向的line 601 in vxi11

代码语言:javascript
复制
    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)

我猜我在类中包含vxi11.py模块的方式是不正确的,参见def Open_GPIB()中的return vxi11.Instrument(ip,addr_str)

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

代码语言:javascript
复制
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")等价的

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-12 17:21:26

这样啊,原来是这么回事。在Open_GPIB()函数中缺少逗号,在gpib0中它应该是gpib0,

代码语言:javascript
复制
addr_str = "gpib0," + "{}".format(addr)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59255334

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档