using System; using System.Device.Gpio; using System.Device.I2c; namespace Libs_SequentMicrosystems { public class RTDStackLevelReader { public readonly byte DEVICE_ADDRESS = 0x40; public readonly byte RTD_RESISTANCE_ADD = 59; /// /// Read Single Resistance /// /// Level on Stack 0-7 /// Chanel on stack layer 1-8 /// Resistance of selected element /// /// public float Get(byte stack, byte channel) { if (stack < 0 || stack > 7) throw new ArgumentException("Invalid stack level"); if (channel < 1 || channel > 8) throw new ArgumentException("Invalid channel number"); float val = -273.15f; try { using (I2cDevice i2c = I2cDevice.Create(new I2cConnectionSettings(1, DEVICE_ADDRESS + stack))) { byte[] buffer = new byte[4]; i2c.WriteByte((byte)(RTD_RESISTANCE_ADD + (4 * (channel - 1)))); i2c.Read(buffer); val = BitConverter.ToSingle(buffer, 0); } } catch (IOException e) { throw new IOException($"Fail to communicate with the RTD card with message: \"{e.Message}\""); } return val; } //public float[] GetStack(byte stack) //{ //} } }