我正在使用称为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)然而,当我尝试使用基于类的方法时,它将导致以下错误;
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]以下是基于我的课堂教学方法的代码;
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;
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,什么将相当于;
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")等价的
谢谢
发布于 2019-12-12 17:21:26
这样啊,原来是这么回事。在Open_GPIB()函数中缺少逗号,在gpib0中它应该是gpib0,
addr_str = "gpib0," + "{}".format(addr)https://stackoverflow.com/questions/59255334
复制相似问题