FPGAReadProperty.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using NIFPGA.lvbitx;
  2. using System.Runtime.CompilerServices;
  3. namespace NIFPGA
  4. {
  5. public sealed class FPGAReadProperty<T> : FPGABaseProperty
  6. where T : unmanaged
  7. {
  8. private object lockObject = new object();
  9. internal FPGAReadProperty(FPGASession session, Register indicator) : base(session, indicator)
  10. {
  11. }
  12. private T GetValue()
  13. {
  14. lock (lockObject)
  15. {
  16. T value = default;
  17. switch (value)
  18. {
  19. case Boolean:
  20. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadBool>()(_Session.Session, Register, ref Unsafe.As<T, byte>(ref value)));
  21. break;
  22. case Byte:
  23. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU8>()(_Session.Session, Register, ref Unsafe.As<T, byte>(ref value)));
  24. break;
  25. case SByte:
  26. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI8>()(_Session.Session, Register, ref Unsafe.As<T, sbyte>(ref value)));
  27. break;
  28. case Int16:
  29. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI16>()(_Session.Session, Register, ref Unsafe.As<T, short>(ref value)));
  30. break;
  31. case UInt16:
  32. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU16>()(_Session.Session, Register, ref Unsafe.As<T, ushort>(ref value)));
  33. break;
  34. case Int32:
  35. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI32>()(_Session.Session, Register, ref Unsafe.As<T, int>(ref value)));
  36. break;
  37. case UInt32:
  38. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU32>()(_Session.Session, Register, ref Unsafe.As<T, uint>(ref value)));
  39. break;
  40. case Int64:
  41. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI64>()(_Session.Session, Register, ref Unsafe.As<T, long>(ref value)));
  42. break;
  43. case UInt64:
  44. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU64>()(_Session.Session, Register, ref Unsafe.As<T, ulong>(ref value)));
  45. break;
  46. case Single:
  47. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadSgl>()(_Session.Session, Register, ref Unsafe.As<T, float>(ref value)));
  48. break;
  49. case double:
  50. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadDbl>()(_Session.Session, Register, ref Unsafe.As<T, double>(ref value)));
  51. break;
  52. }
  53. return value;
  54. }
  55. }
  56. public T Value => GetValue();
  57. }
  58. }