while further playing with it i go to another exceptions troubles. I have simple test program:
import time
from digitemp.master import UART_Adapter
from digitemp.device import DS18B20
from digitemp.exceptions import DeviceError, AdapterError
device = "/dev/tty1wUSB"
sensID = "282E12D50400005A"
print ("Connecting to '%s'..." % device)
# infinite device loop
while True:
try:
bus = UART_Adapter(device)
print ("Connected to '%s'..." % device)
sensor = DS18B20(bus, rom=sensID)
# infinite reading loop
while True:
try:
temp = sensor.get_temperature()
#temp = round(temp * 4) / 4
print ("{}:{}".format(sensID, temp))
except AdapterError:
print ("U")
time.sleep(10)
except KeyboardInterrupt:
print ("Koniec...")
break
bus.close()
Purpose of the testing is to catch the device disconnect and eventually reconnect it again (and continue with measuring) when device is connected again. With this code i did simple tests:
run without device connected
disconnect after initial connecting
Although in both cases is the error the same, your code throws different exceptions in both cases:
in attempt to run on disconnected device i get FileNotFoundError followed by the serial.serialutil.SerialException
in attempt to read disconnected device (after bus was initialized) i get termios.error
This requires to import two additional modules (serial and termios) to catch these situations and catch both exceptions.
There is defined DeviceError exception in your code, then IMO both these situations have to be catched by module and have to raise DeviceError (eg. with text from original exception) exception, to make code more cleaner. Or is this exception intended for something other?
Hi,
while further playing with it i go to another exceptions troubles. I have simple test program:
Purpose of the testing is to catch the device disconnect and eventually reconnect it again (and continue with measuring) when device is connected again. With this code i did simple tests:
Although in both cases is the error the same, your code throws different exceptions in both cases:
FileNotFoundError
followed by theserial.serialutil.SerialException
termios.error
This requires to import two additional modules (
serial
andtermios
) to catch these situations and catch both exceptions.There is defined
DeviceError
exception in your code, then IMO both these situations have to be catched by module and have to raiseDeviceError
(eg. with text from original exception) exception, to make code more cleaner. Or is this exception intended for something other?