FPGAArrayReadProperty.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. public override bool IsArray => true;
  16. private T[] GetValues()
  17. {
  18. lock (lockObject)
  19. {
  20. if (Count == 0) return tempvalue;
  21. switch (tempvalue[0])
  22. {
  23. case (bool):
  24. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayBool>()(_Session.Session, Register, ref Unsafe.As<T, byte>(ref tempvalue[0]), Count));
  25. break;
  26. case (byte):
  27. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU8>()(_Session.Session, Register, ref Unsafe.As<T, byte>(ref tempvalue[0]), Count));
  28. break;
  29. case (sbyte):
  30. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI8>()(_Session.Session, Register, ref Unsafe.As<T, sbyte>(ref tempvalue[0]), Count));
  31. break;
  32. case short:
  33. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI16>()(_Session.Session, Register, ref Unsafe.As<T, short>(ref tempvalue[0]), Count));
  34. break;
  35. case (ushort):
  36. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU16>()(_Session.Session, Register, ref Unsafe.As<T, ushort>(ref tempvalue[0]), Count));
  37. break;
  38. case (int):
  39. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI32>()(_Session.Session, Register, ref Unsafe.As<T, int>(ref tempvalue[0]), Count));
  40. break;
  41. case (uint):
  42. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU32>()(_Session.Session, Register, ref Unsafe.As<T, uint>(ref tempvalue[0]), Count));
  43. break;
  44. case (long):
  45. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI64>()(_Session.Session, Register, ref Unsafe.As<T, long>(ref tempvalue[0]), Count));
  46. break;
  47. case (ulong):
  48. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU64>()(_Session.Session, Register, ref Unsafe.As<T, ulong>(ref tempvalue[0]), Count));
  49. break;
  50. case (float):
  51. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArraySgl>()(_Session.Session, Register, ref Unsafe.As<T, float>(ref tempvalue[0]), Count));
  52. break;
  53. case (double):
  54. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayDbl>()(_Session.Session, Register, ref Unsafe.As<T, double>(ref tempvalue[0]), Count));
  55. break;
  56. }
  57. return tempvalue;
  58. }
  59. }
  60. public uint Count { get; }
  61. public T[] Values => GetValues();
  62. }
  63. }