botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
BotSense.bsI2C Python Module

The bsI2C module under the BotSense python package provides python applications an interface to communicate with proxied i2c devices. The underlining compiled extension module _bsI2C.so library provides the provides the shim between python calling conventions and the C libbsclient_i2c.[a,so] library.

See also
BotSense.bsI2C
Example:
#
# Example use of BotSense.bsI2C Module
#
import sys
import BotSense.BotSenseTypes as bsTypes
import BotSense.BotSenseError as bsError
import BotSense.BotSenseServer as bsServer
import BotSense.bsI2C as bsI2C
# create a BotSense client
cli = bsTypes.BsClient('myi2c')
# connect to the bsProxy server at the given host name and listening port
try:
bsServer.ServerConnect(cli, serverHostName="robot1", serverPort=9196)
except bsError.BotSenseError, inst:
print inst
sys.exit(8)
# open a virtual connection to a proxied I2C device
try:
hndVConn = bsI2C.I2CReqOpen(cli, "/dev/i2c-1")
except bsError.BotSenseError, inst:
print inst
sys.exit(8)
print "Example: established virtual connection %d" % (hndVConn)
# the I2C device attached to the I2C bus
i2cAddr = 0x20
# execute a write-read transaction to the device
try:
rsp = bsI2C.I2CReqTrans(cli, hndVConn, i2cAddr, '\x01', 6)
except bsError.BotSenseError, inst:
print inst
sys.exit(8)
print "Read response %s" % (repr(rsp))
# close the virtual connection
try:
bsI2C.I2CReqClose(cli, hndVConn)
except bsError.BotSenseError, inst:
print inst
sys.exit(8)
# close the connection to the bsProxy server
try:
bsServer.ServerDisconnect(cli)
except bsError.BotSenseError, inst:
print inst
sys.exit(8)
# delete the client
del cli