FPGAArrayWriteProperty.cs 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Runtime.CompilerServices;
  2. namespace NIFPGA
  3. {
  4. public sealed class FPGAArrayWriteProperty<T> : FPGABaseProperty
  5. where T : unmanaged
  6. {
  7. private delegate NiFpga_Status NiFpgaDll_Delegate(uint session, uint indicator, ref T array, [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.U4)] uint size);
  8. NiFpgaDll_Delegate Read;
  9. NiFpgaDll_Delegate Write;
  10. private T[] tempvalue = new T[0];
  11. internal FPGAArrayWriteProperty(FPGASession session, uint indicator,uint count) : base(session, indicator,false)
  12. {
  13. Count= count;
  14. tempvalue = new T[Count];
  15. switch (tempvalue[0])
  16. {
  17. case (bool):
  18. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayBool).Name);
  19. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayBool).Name);
  20. break;
  21. case (byte):
  22. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU8).Name);
  23. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayU8).Name);
  24. break;
  25. case (sbyte):
  26. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI8).Name);
  27. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayI8).Name);
  28. break;
  29. case short:
  30. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI16).Name);
  31. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayI16).Name);
  32. break;
  33. case (ushort):
  34. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU16).Name);
  35. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayU16).Name);
  36. break;
  37. case (int):
  38. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI32).Name);
  39. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayI32).Name);
  40. break;
  41. case (uint):
  42. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU32).Name);
  43. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayU32).Name);
  44. break;
  45. case (long):
  46. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI64).Name);
  47. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayI64).Name);
  48. break;
  49. case (ulong):
  50. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU64).Name);
  51. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayU64).Name);
  52. break;
  53. case (float):
  54. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArraySgl).Name);
  55. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArraySgl).Name);
  56. break;
  57. case (double):
  58. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayDbl).Name);
  59. Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayDbl).Name);
  60. break;
  61. }
  62. }
  63. private T[] GetValues()
  64. {
  65. if (Count == 0) return tempvalue;
  66. _Session.CheckResult(Read(_Session.Session, Indicator, ref tempvalue[0], Count));
  67. return tempvalue;
  68. }
  69. private void SetValue(T[] values)
  70. {
  71. if (values.Length != Count) return;
  72. _Session.CheckResult(Write(_Session.Session, Indicator, ref values[0], Count));
  73. }
  74. public uint Count { get; }
  75. public T[] Values { get => GetValues(); set => SetValue(value); }
  76. }
  77. }