Commit 019414d0 authored by auke.klazema's avatar auke.klazema

extracted port name validation to a method

parent 141b2752
......@@ -24,13 +24,11 @@ class PrologixGpibUsb(PortDevice):
if port == "":
maxDeviceNum, port, portFormat = self._set_default_platform_values()
self._validate_port(port)
if verbose:
print "Looking for ports such as %s in range %d on %s" % \
( port, maxDeviceNum, platform.system() )
self._rematch=re.search(r"(/dev/tty.*[^0-9])([0-9]+$)",port)
if not self._rematch:
raise ValueError(port)
while int(self._rematch.group(2)) < maxDeviceNum:
if verbose:
......@@ -39,8 +37,8 @@ class PrologixGpibUsb(PortDevice):
self._serialPort = serial.Serial(port,timeout=timeout)
break
except serial.SerialException:
port=self._rematch.group(1) +\
(portFormat % (int(self._rematch.group(2))+1))
port=self._rematch.group(1) + \
(portFormat % (int(self._rematch.group(2))+1))
self._rematch=re.search("(/dev/tty.*[^0-9])([0-9]+$)",port)
if self._serialPort==None:
raise serial.SerialException("Cannot find port")
......@@ -55,8 +53,8 @@ class PrologixGpibUsb(PortDevice):
self._devices = []
for self._hpib_address in range(0, 31):
commandStr = "++addr " + str(self._hpib_address) + chr(10) + \
"*idn?" + chr(10) + \
"++read" + chr(10)
"*idn?" + chr(10) + \
"++read" + chr(10)
self._serialPort.write(commandStr)
returnStr = self._serialPort.readline()
if returnStr != "":
......@@ -65,6 +63,11 @@ class PrologixGpibUsb(PortDevice):
self._devices = "Not scanned."
self._hpib_address = -1
def _validate_port(self, port):
self._rematch = re.search(r"(/dev/tty.*[^0-9])([0-9]+$)", port)
if not self._rematch:
raise ValueError(port)
def _set_default_platform_values(self):
if platform.system() == "Linux":
port = "/dev/ttyUSB0"
......
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