All of lore.kernel.org
 help / color / mirror / Atom feed
* Python bindings to i2c-dev
@ 2005-05-19  6:25 Mark M. Hoffman
  2005-05-19  6:25 ` Mark M. Hoffman
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Mark M. Hoffman @ 2005-05-19  6:25 UTC (permalink / raw)
  To: lm-sensors

Hi:

(cc James, who IIRC is a Python guy...)

After a couple false starts and some hair-pulling, here is a Python module
which allows SMBus access through the I2C /dev interface.  I would like to
eventually add this to the lm_sensors project.

	http://members.dca.net/mhoffman/sensors/python/

To build it and use it in place, start with this:

	$ python setup.py build

Then, e.g. (as root):

	# python
	(...)
	>>> from smbus import SMBus
	>>> b = SMBus(0) # 0 indicates /dev/i2c-0
	>>> b.read_byte_data(0x2f,0x58)
	114

If there's no device to ack the address, or in case of any other bus
error, it raises an exception:

	>>> b.write_quick(0x2e)
	Traceback (most recent call last):
	  File "<stdin>", line 1, in ?
	IOError: [Errno 1] Operation not permitted

TODO: the rest of the bus transactions, and the capabilities query.

WARNING: I have managed to lock up my machine's SMBus more than once, so
the usual caveats apply.  If you lock up your bus (such that write_quick
commands to known good addresses start to fail) you may need to COMPLETELY
power off your machine, including physically removing the plug from the
power supply.  In my case, the machine fails the BIOS POST until I do that.
Of course, this is no worse than what is possible from i2c-dev directly.

Which reminds me...  Khali: Is i2c-dev safe (ruin-proof) for people with
IBM laptops?  Or would that check need to be built in to this?

Comments and suggestions are welcome.

Regards,

-- 
Mark M. Hoffman
mhoffman@lightlink.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-05-19  6:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-19  6:25 Python bindings to i2c-dev Mark M. Hoffman
2005-05-19  6:25 ` Mark M. Hoffman
2005-05-19  6:25 ` Mark Studebaker
2005-05-19  6:25 ` Jean Delvare
2005-05-19  6:25 ` Mark M. Hoffman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.