FPGAFXPWriteProperty.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using FxpConvert.Common;
  2. namespace NIFPGA
  3. {
  4. public sealed class FPGAFXPWriteProperty: FPGABaseProperty
  5. {
  6. Interop.NiFpgaDll_ReadU64 Read;
  7. Interop.NiFpgaDll_WriteU64 Write;
  8. private NiFpga_FxpTypeInfo _TypeInfo;
  9. private IFxpConvert _Convert;
  10. internal FPGAFXPWriteProperty(FPGASession session, uint indicator,NiFpga_FxpTypeInfo typeInfo,IFxpConvert convert) : base(session, indicator,false)
  11. {
  12. _TypeInfo = typeInfo;
  13. _Convert = convert;
  14. Read = _Session.GetDelegate<Interop.NiFpgaDll_ReadU64>();
  15. Write = _Session.GetDelegate<Interop.NiFpgaDll_WriteU64>();
  16. }
  17. private double GetValue()
  18. {
  19. lock (Read)
  20. {
  21. ulong value = 0;
  22. double temp = 0;
  23. _Session.CheckResult(Read(_Session.Session, Indicator, ref value));
  24. _Convert.FxpConvertToDouble(ref value, _TypeInfo, ref temp, 1);
  25. return temp;
  26. }
  27. }
  28. private void SetValue(double value)
  29. {
  30. lock (Read)
  31. {
  32. ulong temp = 0;
  33. _Convert.DoubleConvertToDxp(ref value, _TypeInfo, ref temp, 1);
  34. _Session.CheckResult(Write(_Session.Session, Indicator, temp));
  35. }
  36. }
  37. public double Value { get => GetValue(); set => SetValue(value); }
  38. }
  39. }