FPGAWriteProperty.cs 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics.CodeAnalysis;
  5. using System.Diagnostics.Metrics;
  6. using System.Linq;
  7. using System.Runtime.CompilerServices;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace NIFPGA
  11. {
  12. public sealed class FPGAWriteProperty<T> : FPGABaseProperty
  13. where T : unmanaged
  14. {
  15. private delegate NiFpga_Status NiFpgaDll_Delegate(uint session, uint indicator, ref T value);
  16. [AllowNull]
  17. private NiFpgaDll_Delegate Read;
  18. [AllowNull]
  19. private NiFpgaDll_Delegate Write;
  20. internal FPGAWriteProperty(FPGASession session, uint indicator) : base(session, indicator,false)
  21. {
  22. T val =default(T);
  23. switch (val)
  24. {
  25. case Boolean:
  26. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadBool).Name);
  27. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteBool).Name);
  28. break;
  29. case Byte:
  30. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU8).Name);
  31. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteU8).Name);
  32. break;
  33. case SByte:
  34. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI8).Name);
  35. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteI8).Name);
  36. break;
  37. case Int16:
  38. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI16).Name);
  39. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteI16).Name);
  40. break;
  41. case UInt16:
  42. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU16).Name);
  43. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteU16).Name);
  44. break;
  45. case Int32:
  46. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI32).Name);
  47. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteI32).Name);
  48. break;
  49. case UInt32:
  50. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU32).Name);
  51. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteU32).Name);
  52. break;
  53. case Int64:
  54. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI64).Name);
  55. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteI64).Name);
  56. break;
  57. case UInt64:
  58. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU64).Name);
  59. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteU64).Name);
  60. break;
  61. case Single:
  62. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadSgl).Name);
  63. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteSgl).Name);
  64. break;
  65. case double:
  66. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadDbl).Name);
  67. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteDbl).Name);
  68. break;
  69. }
  70. }
  71. private T GetValue()
  72. {
  73. T value = default;
  74. _Session.CheckResult(Read(_Session.Session, Indicator, ref value));
  75. return value;
  76. }
  77. private void SetValue(T value)
  78. {
  79. _Session.CheckResult(Write(_Session.Session, Indicator, ref value));
  80. }
  81. public T Value { get => GetValue(); set => SetValue(value); }
  82. }
  83. }