FPGAFXPWriteProperty.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  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. ulong value = 0;
  20. double temp = 0;
  21. _Session.CheckResult(Read(_Session.Session, Indicator, ref value));
  22. _Convert.FxpConvertToDouble (ref value, _TypeInfo, ref temp, 1);
  23. return temp;
  24. }
  25. private void SetValue(double value)
  26. {
  27. ulong temp = 0;
  28. _Convert.DoubleConvertToDxp(ref value, _TypeInfo, ref temp, 1);
  29. _Session.CheckResult(Write(_Session.Session, Indicator, temp));
  30. }
  31. public double Value { get => GetValue(); set => SetValue(value); }
  32. }
  33. }