-
-
Save dlech/d86161aea84db05f8ffb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import smbus | |
import time | |
for bus in range(3, 7): | |
curport = (bus - 2) | |
print "bus: %2d port: %2d " % (bus, curport) | |
try: | |
i2c = smbus.SMBus(bus) | |
print " Input port %d:" % (bus - 2) | |
for addr in range(0x01, 0x80): | |
try: | |
label = { 0: "Version", 8: " Vendor", 16: "Product" } | |
for offset in range(0, 24, 8): | |
data = i2c.read_i2c_block_data(addr, offset, 8) | |
data.append(0) | |
i = 0 | |
s = '' | |
while data[i]: | |
s += str(chr(data[i])) | |
i += 1 | |
if offset == 0: | |
print " Address: 0x%02X" % addr | |
print " %s: '%s'" % (label[offset], s) | |
time.sleep(0.02) | |
except IOError, err: | |
if err.errno != 6: | |
print " Address 0x%02X: %s" % (addr, err) | |
except IOError, err: | |
if err.errno != 2: | |
print " Input port %d: %s" % (bus - 2), err | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment