Commit 95f512e7 authored by auke.klazema's avatar auke.klazema

Removed unneeded member variables

parent 224a6c4a
......@@ -16,6 +16,9 @@ class PortDevice(object):
class PrologixGpibUsb(PortDevice):
_serialPort = None
_hpib_address = -1
def __init__(self, port="", timeout=1, portFormat="%d", maxDeviceNum=9, verbose=False,
findDevices=False):
if port == "":
......@@ -37,7 +40,6 @@ class PrologixGpibUsb(PortDevice):
if not self._rematch:
raise ValueError(port)
self._serialPort = None
while int(self._rematch.group(2)) < maxDeviceNum:
if verbose:
print "trying ", port
......@@ -60,36 +62,33 @@ class PrologixGpibUsb(PortDevice):
if findDevices:
self._devices = []
for self._hpib_address in range(0, 31):
self._commandStr = "++addr " + str(self._hpib_address) + chr(10) + \
commandStr = "++addr " + str(self._hpib_address) + chr(10) + \
"*idn?" + chr(10) + \
"++read" + chr(10)
self._serialPort.write(self._commandStr)
self._returnStr = self._serialPort.readline()
if self._returnStr != "":
self._devices += [self._hpib_address, self._returnStr]
self._serialPort.write(commandStr)
returnStr = self._serialPort.readline()
if returnStr != "":
self._devices += [self._hpib_address, returnStr]
else:
self._devices = "Not scanned."
self._hpib_address = -1
def command(self, hpib_address, command):
if hpib_address != self._hpib_address:
self._commandStr = "++addr " + str(hpib_address) + chr(10)
command = "++addr " + str(hpib_address) + chr(10) + command
self._hpib_address = hpib_address
else:
self._commandStr = ""
self._commandStr += command + chr(10)
self._commandCount = self._serialPort.write(self._commandStr)
self._serialPort.write(command + chr(10))
def query(self, hpib_address, query, count=80):
if hpib_address != self._hpib_address:
self._commandStr = "++addr " + str(hpib_address) + chr(10)
query = "++addr " + str(hpib_address) + chr(10) + query
self._hpib_address = hpib_address
else:
self._commandStr = ""
self._commandStr += query + chr(10) + "++read eoi" + chr(10)
self._commandCount = self._serialPort.write(self._commandStr)
self._returnStr = self._serialPort.readline()
return self._returnStr[:-1]
query += chr(10) + "++read eoi" + chr(10)
self._serialPort.write(query)
line = self._serialPort.readline()
return line[:-1]
def set_local(self, hpib_address):
# self._commandStr = "++addr "+str(hpib_address)+chr(10)+"loc "+str(hpib_address)+chr(10)
......
......@@ -98,6 +98,30 @@ class PrologixGpibUsbTest(unittest.TestCase):
with self.assertRaises(ValueError):
hpib.PrologixGpibUsb(port="device")
def test_command_prepend_plusplus_addr_if_new_address(self):
address = 2
command = "command"
write_mock = self.serial_mock.return_value.write
usb = hpib.PrologixGpibUsb()
usb.command(address, command)
write_mock.assert_called_with("++addr " + str(address) + chr(10) + command + chr(10))
def test_query_prepend_plusplus_addr_if_new_address(self):
address = 2
query = "query"
write_mock = self.serial_mock.return_value.write
usb = hpib.PrologixGpibUsb()
usb.query(address, query)
write_mock.assert_called_with("++addr " + str(address) + chr(10) +
query + chr(10) +
"++read eoi" + chr(10))
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment