12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System.Runtime.CompilerServices;
- namespace NIFPGA
- {
- public sealed class FPGAArrayWriteProperty<T> : FPGABaseProperty
- where T : unmanaged
- {
- private 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;
- NiFpgaDll_Delegate Write;
- private T[] tempvalue = new T[0];
- internal FPGAArrayWriteProperty(FPGASession session, uint indicator,uint count) : base(session, indicator,false)
- {
- Count= count;
- tempvalue = new T[Count];
- switch (tempvalue[0])
- {
- case (bool):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayBool).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayBool).Name);
- break;
- case (byte):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU8).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayU8).Name);
- break;
- case (sbyte):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI8).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayI8).Name);
- break;
- case short:
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI16).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayI16).Name);
- break;
- case (ushort):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU16).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayU16).Name);
- break;
- case (int):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI32).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayI32).Name);
- break;
- case (uint):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU32).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayU32).Name);
- break;
- case (long):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayI64).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayI64).Name);
- break;
- case (ulong):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayU64).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayU64).Name);
- break;
- case (float):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArraySgl).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArraySgl).Name);
- break;
- case (double):
- Read = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_ReadArrayDbl).Name);
- Write = _Session.GetDelegate<NiFpgaDll_Delegate>(typeof(Interop.NiFpgaDll_WriteArrayDbl).Name);
- break;
- }
- }
- private T[] GetValues()
- {
- if (Count == 0) return tempvalue;
- _Session.CheckResult(Read(_Session.Session, Indicator, ref tempvalue[0], Count));
- return tempvalue;
- }
- private void SetValue(T[] values)
- {
- if (values.Length != Count) return;
- _Session.CheckResult(Write(_Session.Session, Indicator, ref values[0], Count));
- }
- public uint Count { get; }
- public T[] Values { get => GetValues(); set => SetValue(value); }
- }
- }
|