1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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<Interop.NiFpgaDll_ReadU64>();
- Write = _Session.GetDelegate<Interop.NiFpgaDll_WriteU64>();
- }
- 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<Interop.NiFpgaDll_WriteU8>()(_Session.Session, Indicator, Unsafe.As<ulong, byte>(ref temp))),
- var x when x > 8 && x <= 16 => _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU16>()(_Session.Session, Indicator, Unsafe.As<ulong, ushort>(ref temp))),
- var x when x > 16 && x <= 32 => _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU32>()(_Session.Session, Indicator, Unsafe.As<ulong, uint>(ref temp))),
- var x when x > 32 && x <= 64 => _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU64>()(_Session.Session, Indicator, temp)),
- _ => _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU64>()(_Session.Session, Indicator, temp)),
- };
- //_Session.CheckResult(Write(_Session.Session, Indicator, temp));
- }
- }
- public double Value { get => GetValue(); set => SetValue(value); }
- }
- }
|