mirror of
https://github.com/NotAShelf/air-quality-monitor.git
synced 2024-11-22 13:20:48 +00:00
handle serial port unavailable
This commit is contained in:
parent
a22882a169
commit
5c7691ba6b
1 changed files with 6 additions and 1 deletions
|
@ -17,6 +17,11 @@ class AirQualityMonitor:
|
||||||
SERIAL_DEVICE = os.environ.get("SERIAL_DEVICE", "/dev/ttyUSB0")
|
SERIAL_DEVICE = os.environ.get("SERIAL_DEVICE", "/dev/ttyUSB0")
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
# if path does not exist, error and exit
|
||||||
|
if not os.path.exists(self.SERIAL_DEVICE):
|
||||||
|
raise RuntimeError(f"Serial device {self.SERIAL_DEVICE} not found.")
|
||||||
|
else:
|
||||||
|
print(f"Serial device {self.SERIAL_DEVICE} found.")
|
||||||
self.ser = serial.Serial(self.SERIAL_DEVICE)
|
self.ser = serial.Serial(self.SERIAL_DEVICE)
|
||||||
|
|
||||||
def get_measurement(self):
|
def get_measurement(self):
|
||||||
|
|
Loading…
Reference in a new issue