12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Metrics;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace NIFPGA
- {
- public sealed class FPGAWriteProperty<T> : FPGABaseProperty
- where T : unmanaged
- {
- private delegate NiFpga_Status NiFpgaDll_Delegate(uint session, uint indicator, ref T value);
- [AllowNull]
- private NiFpgaDll_Delegate Read;
- [AllowNull]
- private NiFpgaDll_Delegate Write;
- internal FPGAWriteProperty(FPGASession session, uint indicator) : base(session, indicator,false)
- {
- T val =default(T);
- switch (val)
- {
- case Boolean:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadBool).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteBool).Name);
- break;
- case Byte:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU8).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteU8).Name);
- break;
- case SByte:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI8).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteI8).Name);
- break;
- case Int16:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI16).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteI16).Name);
- break;
- case UInt16:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU16).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteU16).Name);
- break;
- case Int32:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI32).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteI32).Name);
- break;
- case UInt32:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU32).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteU32).Name);
- break;
- case Int64:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadI64).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteI64).Name);
- break;
- case UInt64:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadU64).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteU64).Name);
- break;
- case Single:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadSgl).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteSgl).Name);
- break;
- case double:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadDbl).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteDbl).Name);
- break;
- }
- }
- private T GetValue()
- {
- T value = default;
- _Session.CheckResult(Read(_Session.Session, Indicator, ref value));
- return value;
- }
- private void SetValue(T value)
- {
- _Session.CheckResult(Write(_Session.Session, Indicator, ref value));
- }
- public T Value { get => GetValue(); set => SetValue(value); }
- }
- }
|