#
# Example use of BotSense.bsI2C Module
#
import sys
# 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)
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