public ushort ReadbackX1BRegister(ChannelAddress channelAddress)
 {
     using (_lockFactory.GetLock(LockType.CommandLock))
     {
         if (channelAddress < ChannelAddress.Dac0 || channelAddress > ChannelAddress.Dac39)
         {
             throw new ArgumentOutOfRangeException(nameof(channelAddress));
         }
         if (_evalBoard.DeviceState.UseRegisterCache &&
             _evalBoard.DeviceState.X1BRegisters[channelAddress.ToChannelNumber()].HasValue)
         {
             var deviceStateX1BRegister = _evalBoard.DeviceState.X1BRegisters[channelAddress.ToChannelNumber()];
             if (deviceStateX1BRegister != null)
             {
                 return(deviceStateX1BRegister.Value);
             }
         }
         _sendSpecialFunctionCommand.SendSpecialFunction(SpecialFunctionCode.SelectRegisterForReadback,
                                                         (ushort)((ushort)AddressCodesForDataReadback.X1BRegister |
                                                                  (ushort)(((byte)channelAddress & (byte)BasicMasks.SixBits) << 7)));
         var val = _readSPICommand.ReadSPI();
         if (_evalBoard.DeviceState.Precision == DacPrecision.FourteenBit)
         {
             val &= (ushort)BasicMasks.HighFourteenBits;
         }
         _evalBoard.DeviceState.X1BRegisters[channelAddress.ToChannelNumber()] = val;
         return(val);
     }
 }
        public void SetDacChannelDataValueA(ChannelAddress channelAddress, ushort value)
        {
            if (channelAddress < ChannelAddress.Dac0 || channelAddress > ChannelAddress.Dac39)
            {
                throw new ArgumentOutOfRangeException(nameof(channelAddress));
            }
            using (_lockFactory.GetLock(LockType.CommandLock))
            {
                var val = _evalBoard.DeviceState.Precision == DacPrecision.SixteenBit
                    ? value
                    : (ushort)(value & (ushort)BasicMasks.HighFourteenBits);

                if (_evalBoard.DeviceState.UseRegisterCache &&
                    val == _evalBoard.DeviceState.X1ARegisters[channelAddress.ToChannelNumber()])
                {
                    return;
                }
                var controlRegisterBits = _readbackControlRegisterCommand.ReadbackControlRegister() &
                                          ControlRegisterBits.WritableBits;
                controlRegisterBits &=
                    ~ControlRegisterBits
                    .InputRegisterSelect;     //set control register bit F2 =0 to select register X1A for input
                _writeControlRegisterCommand.WriteControlRegister(controlRegisterBits);

                _sendSPICommand.SendSPI((uint)SerialInterfaceModeBits.WriteToDACInputDataRegisterX |
                                        (uint)(((byte)channelAddress & (byte)BasicMasks.SixBits) << 16) |
                                        val);
                _evalBoard.DeviceState.X1ARegisters[channelAddress.ToChannelNumber()] = val;
            }
        }
        public void SetDacChannelGain(ChannelAddress channelAddress, ushort value)
        {
            if (channelAddress < ChannelAddress.Dac0 || channelAddress > ChannelAddress.Dac39)
            {
                throw new ArgumentOutOfRangeException(nameof(channelAddress));
            }

            var val = _evalBoard.DeviceState.Precision == DacPrecision.SixteenBit
                ? value
                : (ushort)(value & (ushort)BasicMasks.HighFourteenBits);

            if (!_evalBoard.DeviceState.UseRegisterCache ||
                val != _evalBoard.DeviceState.MRegisters[channelAddress.ToChannelNumber()])
            {
                using (_lockFactory.GetLock(LockType.CommandLock))
                {
                    _setCLRPinLowCommand.SetCLRPinLow();
                    _sendSPICommand.SendSPI((uint)SerialInterfaceModeBits.WriteToDACGainRegisterM |
                                            (uint)(((byte)channelAddress & (byte)BasicMasks.SixBits) << 16) |
                                            val);
                    _evalBoard.DeviceState.MRegisters[channelAddress.ToChannelNumber()] = val;
                    _setCLRPinHighCommand.SetCLRPinHigh();
                }
            }
        }
 public void ShouldCacheMRegisterValues(
     [Values(DacPrecision.SixteenBit, DacPrecision.FourteenBit)] DacPrecision dacPrecision,
     [Range((int)ChannelAddress.Dac0, (int)ChannelAddress.Dac39)] ChannelAddress channelAddress,
     [Values(ushort.MinValue, 1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7, 1 << 8, 1 << 9, 1 << 10,
             1 << 11, 1 << 12, 1 << 13, 1 << 14, 1 << 15, ushort.MaxValue)] int dacChannelGain)
 {
     GivenDACPrecision(dacPrecision);
     WhenSetDacChannelGain(channelAddress, (ushort)dacChannelGain);
     ThenMRegisterValueInDeviceStateCacheIsSetTo(
         channelAddress.ToChannelNumber(),
         (ushort)(dacChannelGain &
                  (dacPrecision == DacPrecision.SixteenBit
                       ? (ushort)BasicMasks.SixteenBits
                       : (ushort)BasicMasks.HighFourteenBits))
         );
 }
Exemple #5
0
 private void GivenMRegisterValueExistsInDeviceStateRegisterCache(ChannelAddress channelAddress, ushort?value)
 {
     _deviceState.MRegisters[channelAddress.ToChannelNumber()] = value;
 }
Exemple #6
0
 private void ThenTheValueReadShouldBeCached(ChannelAddress channelAddress)
 {
     _deviceState.MRegisters[channelAddress.ToChannelNumber()].Should().Be(_resultOfReadback);
 }
Exemple #7
0
 private void GivenMRegisterValueDoesNotExistInDeviceStateRegisterCache(ChannelAddress channelAddress)
 {
     _deviceState.MRegisters[channelAddress.ToChannelNumber()] = null;
 }
Exemple #8
0
 private void ThenTheValueFromCacheShouldBeTheValueReturned(ChannelAddress channelAddress)
 {
     _deviceState.X1BRegisters[channelAddress.ToChannelNumber()].Should().Be(_resultOfReadback);
 }