readWord method
int
readWord(
- int address, [
- BitOrder order = BitOrder.msbLast,
- RegisterWidth width = RegisterWidth.bits8
Reads a word from the I2C device with the address and the bit order].
The optional register parameters bit width enables 16-bit register.
Some I2C devices can directly be read without an explicit register.
The bit order depends on the I2C device.
Implementation
int readWord(int address,
[BitOrder order = BitOrder.msbLast,
RegisterWidth width = RegisterWidth.bits8]) {
var data = <I2Cmsg>[];
data.add(I2Cmsg(address, [I2CmsgFlags.i2c_m_rd], 2));
var result = transfer(data);
try {
var ptr = result._messages[0].buf;
var value = (ptr[(order == BitOrder.msbLast ? 0 : 1)] & 0xff) |
(ptr[(order == BitOrder.msbLast ? 1 : 0)] & 0xff) << 8;
return value;
} finally {
result.dispose();
}
}