File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -285,11 +285,12 @@ def _read_register(self, reg_addr):
285
285
self ._buffer [1 ] = reg_addr & 0xFF
286
286
with self .i2c_device as i2c :
287
287
i2c .write (self ._buffer , end = 2 )
288
- # separate readinto because the SCD30 wants an i2c stop before the read (non-repeated start)
289
- time .sleep (0.005 ) # min 3 ms delay
290
- with self .i2c_device as i2c :
291
- i2c .readinto (self ._buffer , end = 2 )
292
- return unpack_from (">H" , self ._buffer )[0 ]
288
+ # separate readinto because the SCD30 wants an i2c stop before the read (non-repeated start)
289
+ time .sleep (0.005 ) # min 3 ms delay
290
+ i2c .readinto (self ._buffer , end = 3 )
291
+ if not self ._check_crc (self ._buffer [:2 ], self ._buffer [2 ]):
292
+ raise RuntimeError ("CRC check failed while reading data" )
293
+ return unpack_from (">H" , self ._buffer [0 :2 ])[0 ]
293
294
294
295
def _read_data (self ):
295
296
self ._send_command (_CMD_READ_MEASUREMENT )
You can’t perform that action at this time.
0 commit comments