I would like to connect multiple thermometers to a Raspberry board via the I2C bus on Raspbian, using a C++ application with an event loop containing pselect()
. Opening the default i2c-0
file descriptor (and using the linux/i2c-dev.h interface ) from the application, I'd add the file descriptor to pselect()
's fd_set *readfds
and fd_set *writefds
. I wonder if this file descriptor would ever become FD_WRITEABLE
or FD_READABLE
? Since I2C is a master/slave setup, it should be impossible for a thermometer to initiate communication, because both the read and write operations are initiated by the application in userland, so I suppose FD_READABLE
should be out of the question, am I right?
I haven't found anything about using the I2C with pselect, what does readable/writable mean in a socket file descriptor? And why regular files don't bother with that? was the closest answer I stumbled upon: "Readable means there is data or a FIN present in the socket receive buffer. Writable means there is space available in the socket send buffer." Is an I2C device buffered? Can I depend on this mechanism?
Thanks a lot!