55 RoadNarrows Robotics I2C. 73 I2C_ADDR_NONE = 0xffff
94 return "I2CException(%s)" % (repr(self.
message))
114 self.
m_addr = I2C_ADDR_NONE
131 fd = i2ccore.i2ccore_open(device)
135 (device, os.strerror(e), e))
146 rc = i2ccore.i2ccore_close(self.
m_fd)
153 self.
m_addr = I2C_ADDR_NONE
179 except AssertionError, inst:
181 (self.
m_device, addr, inst.message))
182 n = i2ccore.i2ccore_read(self.
m_fd, self.
m_addr, addr,
183 rbuf.getSwigObj(), basetypes.sizeof(rbuf))
186 raise I2CException(
"%s: read(0x%02x, ...): %s: (errno=%d)." % \
187 (self.
m_device, addr, os.strerror(e), e))
190 rbuf.copyFromSwigObj(n)
191 except AssertionError, inst:
193 (self.
m_device, addr, inst.message))
206 wbuf = basetypes.ByteBuf.Clone(buf)
207 wbuf.copyToSwigObj(len(wbuf))
208 except AssertionError, inst:
210 (self.
m_device, addr, inst.message))
211 n = i2ccore.i2ccore_write(self.
m_fd, self.
m_addr, addr,
212 wbuf.getSwigObj(), len(wbuf))
215 raise I2CException(
"%s: write(0x%02x, ...): %s: (errno=%d)." % \
216 (self.
m_device, addr, os.strerror(e), e))
234 wbuf = basetypes.ByteBuf.Clone(buf)
235 wbuf.copyToSwigObj(len(wbuf))
237 except AssertionError, inst:
239 (self.
m_device, addr, inst.message))
240 rc = i2ccore.i2ccore_transfer(self.
m_fd, self.
m_addr, addr,
241 wbuf.getSwigObj(), len(wbuf),
242 rbuf.getSwigObj(), basetypes.sizeof(rbuf))
245 raise I2CException(
"%s: transfer(0x%02x, ...): %s: (errno=%d)." % \
246 (self.
m_device, addr, os.strerror(e), e))
249 rbuf.copyFromSwigObj(n)
250 except AssertionError, inst:
252 (self.
m_device, addr, inst.message))
268 self.
write(addr, buf)
269 return self.
read(addr, count)
279 rc = i2ccore.i2ccore_check(self.
m_fd, self.
m_addr, addr)
293 for addr
in range(I2C_ADDR_LOW, I2C_ADDR_HIGH+1):
def __del__(self)
Destructor.
def check(self, addr)
Test for the existence of a device with the given address.
def write(self, addr, buf)
Write data to an attached device connected to the open I2C bus.
def transfer(self, addr, buf, count)
Transfer data to an attached device connected to the open I2C bus and receive response.
def read(self, addr, count)
Read data from an attached device connected to the open I2C bus.
def scan(self)
Scan I2C bus for all attached devices.
def close(self)
Close an open I2C bus device.
def write_read(self, addr, buf, count)
Write/read data to/from an attached device connected to the open I2C bus.
def open(self, device)
Open a I2C bus device.
def is_open(self)
Test if I2C bus is open.
message
error message attribute
def __init__(self)
Class constructor.
RoadNarrows Robotics Swigged Core Python Interface Module.
def __init__(self, msg)
Constructor.