private byte[] ReadRegister(byte registerAddress, byte registerLength) { byte[] buffer = new byte[registerLength]; _spiComm.Operate(spiDevice => { byte[] oneByte = new byte[1]; for (int i = 0; i < registerLength; i++) { oneByte[0] = (byte)((registerAddress + i) & 0x7F); spiDevice.Write(oneByte); spiDevice.Read(oneByte); buffer[i] = oneByte[0]; if (_debugLog) { Debug.WriteLine($"¤¤¤¤ Reading register {oneByte[0]:x2} from {registerAddress + i:x2}"); } } }); return(buffer); }
public Ads1256(ISpiComm spiComm, int dataReadyPinNumber) { SpiComm = spiComm; _dataReadyPin = GpioController.GetDefault().OpenPin(dataReadyPinNumber); _dataReadyPin.SetDriveMode(GpioPinDriveMode.InputPullUp); _currentRegisters = SpiComm.Operate(ReadRegisters); Gain = _currentRegisters.Gain; DataRate = _currentRegisters.DataRate; DetectCurrentSources = _currentRegisters.DetectCurrentSources; AutoSelfCalibrate = _currentRegisters.AutoCalibrate; UseInputBuffer = _currentRegisters.UseInputBuffer; }