I am using python instrumentation module called vxi11
to access a volt-meter which is connected via GPIB to Ethernet.
I can access the device if i use the module vxi11
directly inside my main program such as shown bellow;
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)
However when I try to use a class based approach it will result in the following error;
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]
Following is the code for my class based approach;
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)
And following is the line 601
in vxi11
that python is pointing to;
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)
My guess is the way I am including the vxi11.py
module inside my class is not correct, see line return vxi11.Instrument(ip,addr_str)
in def Open_GPIB()
?
or alternatively I may use pyVisa module but I dont know how to use it, my GPIB device is at port 23 and ip address is 192.168.1.5. If I were to use pyVisa, what will be the equivalent of;
def Open_GPIB(ip,addr):
#addr_str = "gpib0," + unicode(addr)
addr_str = "gpib0," + "{}".format(addr)
return vxi11.Instrument(ip,addr_str)
and equivalent of DVM.write("END ON")
Thanks
I got it.
A comma is missing in Open_GPIB() function in gpib0
it should be gpib0,
addr_str = "gpib0," + "{}".format(addr)