1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System.Runtime.CompilerServices;
- namespace NIFPGA
- {
- public sealed class FPGAArrayReadProperty<T> : FPGABaseProperty
- where T : unmanaged
- {
- delegate NiFpga_Status NiFpgaDll_Delegate(uint session, uint indicator, ref T array, [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.U4)] uint size);
- NiFpgaDll_Delegate Read;
- private T[] tempvalue = new T[0];
- internal FPGAArrayReadProperty(FPGASession session, uint indicator, uint count) : base(session, indicator, true)
- {
- Count = count;
- tempvalue = new T[Count];
- switch (tempvalue[0])
- {
- case (bool):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayBool).Name);
- break;
- case (byte):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU8).Name);
- break;
- case (sbyte):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI8).Name);
- break;
- case short:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI16).Name);
- break;
- case (ushort):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU16).Name);
- break;
- case (int):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI32).Name);
- break;
- case (uint):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU32).Name);
- break;
- case (long):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI64).Name);
- break;
- case (ulong):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU64).Name);
- break;
- case (float):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArraySgl).Name);
- break;
- case (double):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayDbl).Name);
- break;
- }
- }
- private T[] GetValues()
- {
- if (Count == 0) return tempvalue;
- _Session.CheckResult(Read(_Session.Session, Indicator, ref tempvalue[0], Count));
- return tempvalue;
- }
- public uint Count { get; }
- public T[] Values { get => GetValues(); }
- }
- }
|