using FxpConvert.Common; using System.Runtime.CompilerServices; namespace NIFPGA { public sealed class FPGAFXPWriteProperty: FPGABaseProperty { Interop.NiFpgaDll_ReadU64 Read; Interop.NiFpgaDll_WriteU64 Write; private object _Lock = new object(); private NiFpga_FxpTypeInfo _TypeInfo; private IFxpConvert _Convert; internal FPGAFXPWriteProperty(FPGASession session, uint indicator,NiFpga_FxpTypeInfo typeInfo,IFxpConvert convert) : base(session, indicator,false) { _TypeInfo = typeInfo; _Convert = convert; Read = _Session.GetDelegate(); Write = _Session.GetDelegate(); } private double GetValue() { lock (_Lock) { ulong value = 0; double temp = 0; _Session.CheckResult(Read(_Session.Session, Indicator, ref value)); _Convert.FxpConvertToDouble(ref value, _TypeInfo, ref temp, 1); return temp; } } private void SetValue(double value) { lock (_Lock) { ulong tempul = 0; _Session.CheckResult(Read(_Session.Session, Indicator, ref tempul)); ulong temp = 0; _Convert.DoubleConvertToDxp(ref value, _TypeInfo, ref temp, 1); if (temp == tempul) return; var _ = _TypeInfo.wordLength switch { var x when x <= 8 => _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref temp))), var x when x > 8 && x <= 16 => _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref temp))), var x when x > 16 && x <= 32 => _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref temp))), var x when x > 32 && x <= 64 => _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, temp)), _ => _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, temp)), }; //_Session.CheckResult(Write(_Session.Session, Indicator, temp)); } } public double Value { get => GetValue(); set => SetValue(value); } } }