FPGAArrayReadProperty.cs 3.4 KB

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