FPGAArrayReadProperty.cs 3.4 KB

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