Skip to content
Snippets Groups Projects
Commit 8b367822 authored by Thorsten Alteholz's avatar Thorsten Alteholz
Browse files

add some error handling

parent 921632f1
No related branches found
No related tags found
No related merge requests found
...@@ -95,6 +95,9 @@ else: ...@@ -95,6 +95,9 @@ else:
print(('ERROR. Unknown device type '+str(config._device_type))) print(('ERROR. Unknown device type '+str(config._device_type)))
exit(0) exit(0)
if mydevice.addr == None:
print('ERROR: no device found for reading data')
exit(1)
def loop(): def loop():
''' '''
......
...@@ -468,6 +468,7 @@ class SQMLE(SQM): ...@@ -468,6 +468,7 @@ class SQMLE(SQM):
except: except:
print('Trying auto device address ...') print('Trying auto device address ...')
self.addr = self.search() self.addr = self.search()
if self.addr!=None:
print(('Found address %s ... ' %str(self.addr))) print(('Found address %s ... ' %str(self.addr)))
self.port = 10001 self.port = 10001
self.start_connection() self.start_connection()
...@@ -667,14 +668,20 @@ class SQMLU(SQM): ...@@ -667,14 +668,20 @@ class SQMLU(SQM):
print(('Trying fixed device address %s ... ' %str(config._device_addr))) print(('Trying fixed device address %s ... ' %str(config._device_addr)))
self.addr = config._device_addr self.addr = config._device_addr
self.bauds = 115200 self.bauds = 115200
try:
self.start_connection() self.start_connection()
except OSError:
print('device ', config._device_addr, ' does not exist')
raise
except: except:
print('Trying auto device address ...') print('Trying auto device address ...')
self.addr = self.search() self.addr = self.search()
if self.addr != None:
print(('Found address %s ... ' %str(self.addr))) print(('Found address %s ... ' %str(self.addr)))
if self.addr != None:
self.bauds = 115200 self.bauds = 115200
self.start_connection() self.start_connection()
# Clearing buffer # Clearing buffer
print(('Clearing buffer ... |'), end=' ') print(('Clearing buffer ... |'), end=' ')
buffer_data = self.read_buffer() buffer_data = self.read_buffer()
...@@ -700,26 +707,34 @@ class SQMLU(SQM): ...@@ -700,26 +707,34 @@ class SQMLU(SQM):
os_in_use = sys.platform os_in_use = sys.platform
if os_in_use == 'linux2': if os_in_use == 'linux2':
print('Detected Linux2 platform')
ports = ports_unix
elif os_in_use == 'linux':
print('Detected Linux platform') print('Detected Linux platform')
ports = ports_unix ports = ports_unix
elif os_in_use == 'win32': elif os_in_use == 'win32':
print('Detected Windows platform') print('Detected Windows platform')
ports = ports_win ports = ports_win
else:
print('No supported platform detected -> ', os_in_use)
used_port = None used_port = None
for port in ports: for port in ports:
try:
os.stat(port)
except OSError:
print('port ', port,' does not exist')
continue
conn_test = serial.Serial(port, 115200, timeout=1) conn_test = serial.Serial(port, 115200, timeout=1)
conn_test.write('ix'.encode) conn_test.write('ix'.encode)
if conn_test.readline()[0] == 'i': if conn_test.readline()[0] == 'i':
used_port = port used_port = port
break break
try: if (used_port==None):
assert(used_port!=None)
except:
print('ERR. Device not found!') print('ERR. Device not found!')
raise
else:
return(used_port) return(used_port)
def start_connection(self): def start_connection(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment