123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System.Diagnostics.CodeAnalysis;
- using System.Runtime.CompilerServices;
- namespace NIFPGA
- {
- public sealed class FPGAReadProperty<T> : FPGABaseProperty
- where T : unmanaged
- {
- private delegate NiFpga_Status NiFpgaDll_Delegate(uint session, uint indicator, ref T value);
- [AllowNull]
- private NiFpgaDll_Delegate Read;
- internal FPGAReadProperty(FPGASession session, uint indicator) : base(session, indicator, true)
- {
- T val = default(T);
- switch (val)
- {
- case Boolean:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadBool).Name);
- break;
- case Byte:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU8).Name);
- break;
- case SByte:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI8).Name);
- break;
- case Int16:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI16).Name);
- break;
- case UInt16:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU16).Name);
- break;
- case Int32:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI32).Name);
- break;
- case UInt32:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU32).Name);
- break;
- case Int64:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI64).Name);
- break;
- case UInt64:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU64).Name);
- break;
- case Single:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadSgl).Name);
- break;
- case double:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadDbl).Name);
- break;
- }
- }
- private T GetValue()
- {
- T value = default;
- _Session.CheckResult(Read(_Session.Session, Indicator, ref value));
- return value;
- }
- public T Value => GetValue();
- }
- }
|