kplindegaard / smbus2

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

Add read()/write() to the SMBus class #23

Open fgervais opened 6 years ago

fgervais commented 6 years ago

The i2c_rdwr() function is really nice as some kind of i2c transfers can only be achieved with it and not with other smbus available commands.

However, to use this function, one need knowledge of the i2c_msg class so it cannot decouple as much from the bus type as for the other smbus functions.

With these two new functions, a device class can receive a bus object and do simple reads and writes without having a hard coupling to this library by having to import i2c_msg.

See this example: https://github.com/fgervais/Si7021/commit/e0f407ca0c6f97c866ddfc2932c57796610917ee

In that case, the device class receives a bus instance and need no knowledge of the implementation other than the functions it needs to use on it.

I also think these functions can be a nice add-on in any case.

I hope this makes sense.

fgervais commented 5 years ago

These I good requests, I will do the changes as soon as I put the setup back together for testing.

I use this code for my air conditioning control so I should get back to it in a few months as summer is coming for me.

Thanks

kplindegaard commented 3 years ago

Works fine. Very useful for sending non-standard messages, or intentionally corrupted messages (negative testing).

The linked issue #63 indicates this PR is required for passing buffers larger than 32 bytes over i2c. That's not really the case as per earlier comments.