* 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* Python bindings to i2c-dev
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
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Mark M. Hoffman @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Hi MDS:
> Mark M. Hoffman wrote:
> >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.
(...)
* Mark D. Studebaker <mds4@verizon.net> [2004-12-31 18:25:54 -0500]:
> what was the motivation for this?
(1) to learn some of the internals of Python. (2) to have a quicker
and more nimble way than C code to control (and therefore test) a bus
adapter. It's very convenient to fire up the Python shell and be able
to slam out bus transactions as one-liners. As I suggested in another
thread, it would make a good tool for prototyping chip drivers.
> do you have any interesing i2c Python programs to share with us?
Heh, not yet. As you know, I've been playing with SMBus/ARP in Python...
but not because I think it should be implemented that way. It's just
the only thing I have in this system that responds to block reads/writes;
and thus the only thing I can use to test those xfers in the new i2c-i801
driver (when I get that far).
Why not port smbus-arp.c to kernel 2.6? I don't see much point in doing
that, at least not in its present form. IMHO proper SMBus 2.0 support
would require some slave support in the bus adapter (required by spec),
as well as some coordination and extension of i2c-core to handle the
details. I'd like to work on that, but I don't have the time right now.
And to answer what has become a FAQ: even though I'm not the biggest fan
of Perl, I do *not* plan on re-writing sensors-detect in Python. Even
if someone jumped up and volunteered, I would argue against doing it.
However, it might be useful to make a Perl module with similar intent to
these Python bindings, separate from sensors-detect (cut-n-pasted from it
even).
Regards,
--
Mark M. Hoffman
mhoffman@lightlink.com
^ permalink raw reply [flat|nested] 5+ messages in thread* Python bindings to i2c-dev
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
3 siblings, 0 replies; 5+ messages in thread
From: Mark Studebaker @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
what was the motivation for this?
do you have any interesing i2c Python programs to share with us?
Mark M. Hoffman wrote:
> 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,
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Python bindings to i2c-dev
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
3 siblings, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Hi Mark,
> 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/
Maybe you could start with a link from the lm-sensors' site, either in
the news or on the useful addresses page?
> 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?
It isn't safe. Single quick writes to addresses 0x54-0x57 are likely to
kill IBM laptops (it actually depends on what command is ran next). That
said, at the moment i2c-piix4 won't load on supposedly vulnerable
systems, so it shouldn't happen.
I have plans to replace quick writes (for detection) by byte reads for
this address range in Linux 2.6's i2c_detect/i2c_probe, just like I did
in i2cdetect and sensors-detect already, but it doesn't address the
i2c-dev issue. Maybe we can hack i2c-dev to prohibit quick writes to the
eeprom range entirely? That way all user-space tools would automatically
be safe.
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Python bindings to i2c-dev
2005-05-19 6:25 Python bindings to i2c-dev Mark M. Hoffman
` (2 preceding siblings ...)
2005-05-19 6:25 ` Jean Delvare
@ 2005-05-19 6:25 ` Mark M. Hoffman
3 siblings, 0 replies; 5+ messages in thread
From: Mark M. Hoffman @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Hi:
* Mark M. Hoffman <mhoffman@lightlink.com> [2004-12-29 00:05:26 -0500]:
> 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.
The next version is here:
http://members.dca.net/mhoffman/sensors/python/20050122/
It implements all bus xfers. I've submitted it to python-list@python.org
for comments as well.
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.