using System; using System.Collections.Generic; using System.Diagnostics.Tracing; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using FxpConvert.Common; namespace NIFPGA { public class WriteFifo:Fifo where T : unmanaged { private object _Locker = new object(); internal WriteFifo(FPGASession session, uint fifosession) : base(session, fifosession) { } public void Write(T[] value,uint timeout,ref uint emptyElementsRemaining) { lock (_Locker) { if (value.Length == 0) return; switch (value[0]) { case bool: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, ref Unsafe.As(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining)); break; case byte: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, ref Unsafe.As(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining)); break; case sbyte: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, ref Unsafe.As(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining)); break; case short: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, ref Unsafe.As(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining)); break; case ushort: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, ref Unsafe.As(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining)); break; case int: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, ref Unsafe.As(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining)); break; case uint: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, ref Unsafe.As(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining)); break; case long: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, ref Unsafe.As(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining)); break; case ulong: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, ref Unsafe.As(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining)); break; case float: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, ref Unsafe.As(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining)); break; case double: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, ref Unsafe.As(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining)); break; } } } } public class WriteFXPFifo : WriteFifo { private IFxpConvert _Convert; private NiFpga_FxpTypeInfo _TypeInfo; internal WriteFXPFifo(FPGASession session, uint fifosession, NiFpga_FxpTypeInfo typeInfo,IFxpConvert convert) : base(session, fifosession) { if(convert == null) throw new ArgumentNullException(nameof(convert)); _Convert = convert; _TypeInfo = typeInfo; } public void Write(ref float value, uint timeout, uint length, ref uint emptyElementsRemaining) { if (length == 0) return; ulong[] temp= new ulong[length]; _Convert.FloatConvertToDxp(ref value, _TypeInfo, ref temp[0], (uint)length); base.Write(temp, timeout, ref emptyElementsRemaining); } public void Write(ref double value, uint timeout, uint length, ref uint emptyElementsRemaining) { if (length == 0) return; ulong[] temp = new ulong[length]; _Convert.DoubleConvertToDxp(ref value, _TypeInfo, ref temp[0], (uint)length); base.Write(temp, timeout, ref emptyElementsRemaining); } } }