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