internal byte ReadByte(byte address) { byte[] buffer = { address }; _device.Write(buffer); return(_device.Read(1)[0]); }
public static UInt32 Read24Bits(II2C device, byte reg, ByteOrder byteOrder, string exceptionMessage) { try { byte[] addr = { reg }; device.Write(addr); byte[] data = device.Read(3); switch (byteOrder) { case ByteOrder.BigEndian: return((UInt32)((data[0] << 16) | (data[1] << 8) | data[2])); case ByteOrder.LittleEndian: return((UInt32)((data[2] << 16) | (data[1] << 8) | data[0])); default: throw new SensorException($"Unsupported byte order {byteOrder}"); } } catch (Exception exception) { throw new SensorException(exceptionMessage, exception); } }
public static byte Read8Bits(II2C device, byte reg, string exceptionMessage) { try { byte[] addr = { reg }; device.Write(addr); return(device.Read(1)[0]); } catch (Exception exception) { throw new SensorException(exceptionMessage, exception); } }
public static byte[] ReadBytes(II2C device, byte reg, int count, string exceptionMessage) { try { byte[] addr = { reg }; device.Write(addr); return(device.Read(count)); } catch (Exception exception) { throw new SensorException(exceptionMessage, exception); } }