private void Begin() { //Read the device signature var ReadBuffer = bme280.ReadAddressByte((byte)eRegisters.BME280_REGISTER_CHIPID); //Logger.Log("BMP280 Signature: " + ReadBuffer.ToString()); //Verify the device signature if (ReadBuffer != BME280_Signature) { throw new Exception("BME280::Begin Signature Mismatch."); } //Set the initalize variable to true init = true; //Read the coefficients table CalibrationData = ReadCoefficeints(); //Write control register WriteControlRegister(); //Write humidity control register WriteControlRegisterHumidity(); }
public static UInt32 Read24Bits(II2CDevice device, byte reg, ByteOrder byteOrder, string exceptionMessage) { try { byte[] data = new byte[3];//ReadBytes(device, reg, 3, exceptionMessage); for (int i = 0; i < data.Length; ++i) { data[i] = device.ReadAddressByte(reg); //Read8Bits(device,reg,"error"); } 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); } }
private void SetMagnetometerRange(MagneticSensitivityScale sensitivityScale) { // get current register data var registerData = _accGyroDevice.ReadAddressByte(CTRL_REG2_M); // zero out scale bits registerData &= BitConverter.GetBytes(~0b0_11_00000)[0];
public void SetPreScaler(int prescaler) { var mode1Save = device.ReadAddressByte(__PCA9685_REG_MODE1); var config = mode1Save | __PCA9685_MODE1_SLEEP_ENABLED; device.WriteAddressByte(__PCA9685_REG_MODE1, (byte)config); // sleep device.WriteAddressByte(__PCA9685_REG_PRE_SCALE, (byte)prescaler); // set prescaler device.WriteAddressByte(__PCA9685_REG_MODE1, mode1Save); // restore settings }
public static byte Read8Bits(II2CDevice device, byte reg, string exceptionMessage) { try { return(device.ReadAddressByte(reg)); } catch (Exception exception) { throw new SensorException(exceptionMessage, exception); } }
// public static UInt32 Read32Bits(II2CDevice device, byte reg, ByteOrder byteOrder, string exceptionMessage) // { // try // { // byte[] data = ReadBytes(device, reg, 4, exceptionMessage); // switch (byteOrder) // { // case ByteOrder.BigEndian: // return (UInt32)((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]); // case ByteOrder.LittleEndian: // return (UInt32)((data[3] << 24) | (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[] ReadBytes(II2CDevice device, byte reg, int count, string exceptionMessage) { try { byte[] addr = { reg }; byte[] data = new byte[count]; device.Write(reg); for (int i = 0; i < count; ++i) { data[i] = device.ReadAddressByte(reg); } return(data); //return device.ReadAddressBlock(reg, count); } catch (Exception exception) { throw new SensorException(exceptionMessage, exception); } }
internal byte ReadByte(byte address) { return(_device.ReadAddressByte(address)); }