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

add some error handling

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