FPGAReadProperty.cs 3.0 KB

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