FPGAArrayReadProperty.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Runtime.CompilerServices;
  2. namespace NIFPGA
  3. {
  4. public sealed class FPGAArrayReadProperty<T> : FPGABaseProperty
  5. where T : unmanaged
  6. {
  7. 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. private T[] tempvalue = new T[0];
  10. internal FPGAArrayReadProperty(FPGASession session, uint indicator, uint count) : base(session, indicator, true)
  11. {
  12. Count = count;
  13. tempvalue = new T[Count];
  14. switch (tempvalue[0])
  15. {
  16. case (bool):
  17. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayBool).Name);
  18. break;
  19. case (byte):
  20. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU8).Name);
  21. break;
  22. case (sbyte):
  23. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI8).Name);
  24. break;
  25. case short:
  26. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI16).Name);
  27. break;
  28. case (ushort):
  29. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU16).Name);
  30. break;
  31. case (int):
  32. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI32).Name);
  33. break;
  34. case (uint):
  35. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU32).Name);
  36. break;
  37. case (long):
  38. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI64).Name);
  39. break;
  40. case (ulong):
  41. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU64).Name);
  42. break;
  43. case (float):
  44. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArraySgl).Name);
  45. break;
  46. case (double):
  47. Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayDbl).Name);
  48. break;
  49. }
  50. }
  51. private T[] GetValues()
  52. {
  53. if (Count == 0) return tempvalue;
  54. _Session.CheckResult(Read(_Session.Session, Indicator, ref tempvalue[0], Count));
  55. return tempvalue;
  56. }
  57. public uint Count { get; }
  58. public T[] Values { get => GetValues(); }
  59. }
  60. }