readBytes method

List<int> readBytes(
  1. int address,
  2. int len
)

Reads len bytes from the I2C device with the address.

Implementation

List<int> readBytes(int address, int len) {
  var data = <I2Cmsg>[];
  data.add(I2Cmsg(address, [I2CmsgFlags.i2c_m_rd], len));
  var result = transfer(data);
  var msg2 = result._messages[0];
  try {
    var read = msg2.len;

    var ptr = msg2.buf;
    var list = <int>[];
    for (var i = 0; i < read; ++i) {
      list.add(ptr[i]);
    }
    return list;
  } finally {
    result.dispose();
  }
}