123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System.Runtime.CompilerServices;
- namespace NIFPGA
- {
- public sealed class FPGAReadProperty<T> : FPGABaseProperty
- where T : unmanaged
- {
- internal FPGAReadProperty(FPGASession session, uint indicator) : base(session, indicator, true)
- {
- }
- private T GetValue()
- {
- T value = default;
- switch (value)
- {
- case Boolean:
- _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadBool>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref value)));
- break;
- case Byte:
- _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU8>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref value)));
- break;
- case SByte:
- _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI8>()(_Session.Session, Indicator, ref Unsafe.As<T, sbyte>(ref value)));
- break;
- case Int16:
- _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI16>()(_Session.Session, Indicator, ref Unsafe.As<T, short>(ref value)));
- break;
- case UInt16:
- _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU16>()(_Session.Session, Indicator, ref Unsafe.As<T, ushort>(ref value)));
- break;
- case Int32:
- _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI32>()(_Session.Session, Indicator, ref Unsafe.As<T, int>(ref value)));
- break;
- case UInt32:
- _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU32>()(_Session.Session, Indicator, ref Unsafe.As<T, uint>(ref value)));
- break;
- case Int64:
- _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI64>()(_Session.Session, Indicator, ref Unsafe.As<T, long>(ref value)));
- break;
- case UInt64:
- _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU64>()(_Session.Session, Indicator, ref Unsafe.As<T, ulong>(ref value)));
- break;
- case Single:
- _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadSgl>()(_Session.Session, Indicator, ref Unsafe.As<T, float>(ref value)));
- break;
- case double:
- _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadDbl>()(_Session.Session, Indicator, ref Unsafe.As<T, double>(ref value)));
- break;
- }
- return value;
- }
- public T Value => GetValue();
- }
- }
|