我正在使用调用 python 仪表模块vxi11
来访问通过 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)
以下是line 601
pythonvxi11
指向的内容;
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
在课堂中包含模块的方式不正确,请参见行return vxi11.Instrument(ip,addr_str)
中的def Open_GPIB()
?
或者我可以使用 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")
谢谢