FPGAReadProperty.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Diagnostics.CodeAnalysis;
  2. using System.Runtime.CompilerServices;
  3. namespace NIFPGA
  4. {
  5. public sealed class FPGAReadProperty<T> : FPGABaseProperty
  6. where T : unmanaged
  7. {
  8. private delegate NiFpga_Status NiFpgaDll_Delegate(uint session, uint indicator, ref T value);
  9. [AllowNull]
  10. private NiFpgaDll_Delegate Read;
  11. internal FPGAReadProperty(FPGASession session, uint indicator) : base(session, indicator, true)
  12. {
  13. T val = default(T);
  14. switch (val)
  15. {
  16. case Boolean:
  17. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadBool).Name);
  18. break;
  19. case Byte:
  20. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU8).Name);
  21. break;
  22. case SByte:
  23. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI8).Name);
  24. break;
  25. case Int16:
  26. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI16).Name);
  27. break;
  28. case UInt16:
  29. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU16).Name);
  30. break;
  31. case Int32:
  32. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI32).Name);
  33. break;
  34. case UInt32:
  35. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU32).Name);
  36. break;
  37. case Int64:
  38. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI64).Name);
  39. break;
  40. case UInt64:
  41. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU64).Name);
  42. break;
  43. case Single:
  44. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadSgl).Name);
  45. break;
  46. case double:
  47. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadDbl).Name);
  48. break;
  49. }
  50. }
  51. private T GetValue()
  52. {
  53. T value = default;
  54. _Session.CheckResult(Read(_Session.Session, Indicator, ref value));
  55. return value;
  56. }
  57. public T Value => GetValue();
  58. }
  59. }