protected Task WriteEeprom(byte address, byte[] values, FtI2CTransferOptions options = FtI2CTransferOptions.I2C_TRANSFER_OPTIONS_START_BIT) { // Sequence for writing a value: // 1. Power up device // 2. Write 0x0000 into the cell of interest // 3. Wait at least 5ms // 4. Write the new value // 5. Wait at least 5ms // 6. Read back and compare if the write was successful // 7. Power down (to make sure the changes take place at next power up return(Task.Run(async() => { var result = Device.Write(Address, new byte[] { address }.Concat(new byte[values.Length].Select(_ => (byte)0)).ToArray(), values.Length + 1, out int transfered, options); if (result != FtdiMpsseI2CResult.Ok) { throw new TempSensorException("Could not write 0 into bus address"); } await Task.Delay(6); result = Device.Write(Address, new byte[] { address }.Concat(values).ToArray(), values.Length + 1, out transfered, options); if (!Device.Ok(result)) { throw new TempSensorException("Could not set new address"); } await Task.Delay(6); var readData = new byte[values.Length]; result = Device.Write(Address, new byte[] { address }, values.Length, out transfered, options); result = Device.Read(Address, readData, values.Length, out transfered); if (!Device.Ok(result)) { throw new TempSensorException("Could not read I2C address"); } bool isValid = true; for (int i = 0; i < readData.Length; i++) { isValid = isValid && readData[i] == values[0]; } if (!isValid) { throw new TempSensorException("Temperature sensor address was not set successfully"); } Address = address; })); }
public static extern FtResult I2C_DeviceWrite(System.IntPtr handle, int deviceAddress, int sizeToTransfer, byte[] buffer, out int sizeTransfered, FtI2CTransferOptions options);
public FtResult Read(byte[] buffer, int sizeToTransfer, out int sizeTransfered, FtI2CTransferOptions options) { //EnforceRightConfiguration(); return(LibMpsseI2C.I2C_DeviceRead(_handle, _deviceAddress, sizeToTransfer, buffer, out sizeTransfered, options)); }
public FtResult Write(byte[] buffer, int sizeToTransfer, out int sizeTransfered, FtI2CTransferOptions options) { return(LibMpsseI2C.I2C_DeviceWrite(_handle, _deviceAddress, sizeToTransfer, buffer, out sizeTransfered, options)); }
public FtdiMpsseI2CResult Write(byte deviceAddress, byte[] buffer, int sizeToTransfer, out int sizeTransfered, FtI2CTransferOptions options = FtI2CTransferOptions.I2C_TRANSFER_OPTIONS_START_BIT | FtI2CTransferOptions.I2C_TRANSFER_OPTIONS_STOP_BIT | FtI2CTransferOptions.I2C_TRANSFER_OPTIONS_BREAK_ON_NACK | FtI2CTransferOptions.I2C_TRANSFER_OPTIONS_FAST_TRANSFER_BYTES) { return(CheckResult(LibMpsse.I2C_DeviceWrite(_i2cHandle, deviceAddress, sizeToTransfer, buffer, out sizeTransfered, (int)options))); }
public FtResult Read(byte[] buffer, int sizeToTransfer, out int sizeTransfered, FtI2CTransferOptions options) { //EnforceRightConfiguration(); return LibMpsseI2C.I2C_DeviceRead(_handle, _deviceAddress, sizeToTransfer, buffer, out sizeTransfered, options); }
public FtResult Write(byte[] buffer, int sizeToTransfer, out int sizeTransfered, FtI2CTransferOptions options) { return LibMpsseI2C.I2C_DeviceWrite(_handle, _deviceAddress, sizeToTransfer, buffer, out sizeTransfered, options); }