Skip to content

Commit 8a7d81b

Browse files
committed
catching the correct ReadTimeoutError for pms5003
1 parent 69294f3 commit 8a7d81b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

examples/all-in-one.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import ltr559
99

1010
from bme280 import BME280
11-
from pms5003 import PMS5003
11+
from pms5003 import PMS5003, ReadTimeoutError as pmsReadTimeoutError
1212
from enviroplus import gas
1313
from subprocess import PIPE, Popen
1414
from PIL import Image
@@ -187,7 +187,7 @@ def get_cpu_temperature():
187187
unit = "ug/m3"
188188
try:
189189
data = pms5003.read()
190-
except pms5003.ReadTimeoutError:
190+
except pmsReadTimeoutError:
191191
pass
192192
else:
193193
data = data.pm_ug_per_m3(1.0)
@@ -196,16 +196,24 @@ def get_cpu_temperature():
196196
if mode == 8:
197197
# variable = "pm25"
198198
unit = "ug/m3"
199-
data = pms5003.read()
200-
data = data.pm_ug_per_m3(2.5)
201-
display_text(variables[mode], data, unit)
199+
try:
200+
data = pms5003.read()
201+
except pmsReadTimeoutError:
202+
pass
203+
else:
204+
data = data.pm_ug_per_m3(2.5)
205+
display_text(variables[mode], data, unit)
202206

203207
if mode == 9:
204208
# variable = "pm10"
205209
unit = "ug/m3"
206-
data = pms5003.read()
207-
data = data.pm_ug_per_m3(10)
208-
display_text(variables[mode], data, unit)
210+
try:
211+
data = pms5003.read()
212+
except pmsReadTimeoutError:
213+
pass
214+
else:
215+
data = data.pm_ug_per_m3(10)
216+
display_text(variables[mode], data, unit)
209217

210218
# Exit cleanly
211219
except KeyboardInterrupt:

0 commit comments

Comments
 (0)