Commit 35e34df8 authored by auke.klazema's avatar auke.klazema

extracted available port search to a method

parent 019414d0
......@@ -30,18 +30,8 @@ class PrologixGpibUsb(PortDevice):
print "Looking for ports such as %s in range %d on %s" % \
( port, maxDeviceNum, platform.system() )
while int(self._rematch.group(2)) < maxDeviceNum:
if verbose:
print "trying ", port
try:
self._serialPort = serial.Serial(port,timeout=timeout)
break
except serial.SerialException:
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")
self._find_available_port(maxDeviceNum, port, portFormat, timeout, verbose)
self._serialPort.write("++savecfg 0" + chr(10))
self._serialPort.write("++auto 0" + chr(10))
self._serialPort.write("++eoi 1" + chr(10))
......@@ -63,6 +53,19 @@ class PrologixGpibUsb(PortDevice):
self._devices = "Not scanned."
self._hpib_address = -1
def _find_available_port(self, maxDeviceNum, port, portFormat, timeout, verbose):
while int(self._rematch.group(2)) < maxDeviceNum:
if verbose:
print "trying ", port
try:
self._serialPort = serial.Serial(port, timeout=timeout)
break
except serial.SerialException:
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 is None:
raise serial.SerialException("Cannot find port")
def _validate_port(self, port):
self._rematch = re.search(r"(/dev/tty.*[^0-9])([0-9]+$)", port)
if not self._rematch:
......
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