kplindegaard / smbus2

A drop-in replacement for smbus-cffi/smbus-python in pure Python
MIT License
243 stars 68 forks source link

Added enable_pec to Enable/Disable PEC #53

Closed rgusmero closed 3 years ago

rgusmero commented 4 years ago

Added member function enable_pec to SMBus to Enable/Disable PEC (Packet Error Checking, see SMBus 1.1 and later).

Some devices require it (e.g. MLX90614), in particular when writing data (because they expect - and check - 1 more byte, i.e. the PEC crc, in the data string).

Example: bus=smbus2.SMBus(1) bus.enable_pec()

rgusmero commented 4 years ago

Done as requested with a small change: insetead of changing the member funcion name, I introduced a setter-only property. This allows to use the old syntax bus.pec=1 and thus better accomplishes the drop-in compatibility requirement.