/// <summary> /// Write one Byte to a Register /// </summary> /// <param name="addressToWriteTo"></param> /// <param name="valueToWrite"></param> public void Write(byte addressToWriteTo, byte valueToWrite) { I2CDevice.I2CTransaction[] transaction; transaction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { addressToWriteTo, valueToWrite }) }; int result = I2CBus.Execute(myConfig, transaction, Timeout); }
/// <summary> /// </summary>Read any number of consecutive Registers /// <param name="addressToReadFrom"></param> Start at this address. /// <param name="responseLength"></param> Response length is the number of Registers to read. If not specified, only one Register will be read. /// <returns></returns> public byte[] Read(byte addressToReadFrom, int responseLength = 1) { var buffer = new byte[responseLength]; I2CDevice.I2CTransaction[] transaction; transaction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { addressToReadFrom }), I2CDevice.CreateReadTransaction(buffer) }; int result = I2CBus.Execute(myConfig, transaction, Timeout); return(buffer); }
public AbstractI2CDevice(ushort address, int clockRate, int timeout) // : base(new Configuration(address, clockRate)) { myConfig = new I2CDevice.Configuration(address, clockRate); Timeout = timeout; I2CBus.SetConfig(myConfig); }
public int Write(I2CDevice.I2CTransaction[] xActions, int timeout) { I2CBus.SetConfig(myConfig); return(I2CBus.Execute(xActions, timeout)); }