protected override ushort Read(Stm32Command command, ushort data, bool dataAvailable) { if (dataAvailable) { _gpioExpander.WriteAddressWord(Unsafe.As <Stm32Command, byte>(ref command), data); return(_gpioExpander.ReadAddressWord(Unsafe.As <Stm32Command, byte>(ref command))); } return(_gpioExpander.ReadAddressWord(Unsafe.As <Stm32Command, byte>(ref command))); }
private void ADS1115ReadValuesWiringPi(byte busId, byte i2cAddress, byte[] configDataChunk, byte[] convertDataChunk) { Pi.Init <BootstrapWiringPi>(); II2CDevice ads1115 = Pi.I2C.AddDevice(i2cAddress); var configWord = (ushort)((configDataChunk[2] << 8) + configDataChunk[1]); // Write config register to the ADC //var currentConfig = ads1115.ReadAddressWord(ADS1115.ADS1115_REG_POINTER_CONFIG); //Console.WriteLine($"Setting original configuration ({currentConfig.ToString("X")}) to {config.ToString("X")}"); ads1115.WriteAddressWord(configDataChunk[0], configWord); //currentConfig = ads1115.ReadAddressWord(ADS1115.ADS1115_REG_POINTER_CONFIG); //Console.WriteLine($"New configuration: {currentConfig.ToString("X")}"); DateTime firstDataRead = DateTime.UtcNow; while (true) { // Read the conversion results ushort result = (ushort)(ads1115.ReadAddressWord(convertDataChunk[0])); float voltage = (float)(result < 32768 ? result : -(65536 - result)) * 2.048f / 65536.0f; j++; if (j % 1000 == 0) { Console.WriteLine(String.Format("| ADC value: {0,5} V | sample rate: {1,7} SPS |", voltage.ToString("N", CultureInfo.InvariantCulture), ((double)j / (DateTime.UtcNow - firstDataRead).TotalSeconds).ToString("N"))); } } }
private short RawReadADC() { // Wait for the conversion to complete Thread.Sleep(conversionDelay); // Read the conversion results // Shift 12-bit results right 4 bits for the ADS1015 return((short)(SwapWord(device.ReadAddressWord(ADS1015REGPOINTERCONVERT)) >> bitShift)); }
private short RawReadADC() { // Wait for the conversion to complete Thread.Sleep(_conversionDelay); ushort statusRegister = (ushort)SwapWord(_device.ReadAddressWord(ADS1015REGPOINTERCONFIG)); int timeout = 1000; while ((statusRegister & 0x8000) == 0 && (timeout-- > 0)) { Pi.Timing.SleepMicroseconds(2); statusRegister = (ushort)SwapWord(_device.ReadAddressWord(ADS1015REGPOINTERCONFIG)); } if (timeout <= 0) { throw new TimeoutException("Timeout reading value from ADC."); } // Read the conversion results // Shift 12-bit results right 4 bits for the ADS1015 return((short)(SwapWord(_device.ReadAddressWord(ADS1015REGPOINTERCONVERT)) >> _bitShift)); }
public static UInt16 Read16Bits(II2CDevice device, byte reg, ByteOrder byteOrder, string exceptionMessage) { try { return(device.ReadAddressWord(reg)); } catch (Exception exception) { throw new SensorException(exceptionMessage, exception); } }
public byte[] Read(int adress) { try { var data = _device.ReadAddressWord(adress); I2CGlobalError = false; return(BitConverter.GetBytes(data)); } catch (Unosquare.RaspberryIO.Abstractions.Native.HardwareException) { I2CGlobalError = true; return(null); } }
public static short ReadAddressWordSwapped(this II2CDevice device, short address) { // Read the conversion results // Shift 12-bit results right 4 bits for the ADS1015 return((short)SwapWord(device.ReadAddressWord(address))); }
//Method to read a 16-bit value from a register and return it in little endian format private ushort ReadUInt16_LittleEndian(byte register) { return(bme280.ReadAddressWord(register)); }