using System; using System.Collections.Generic; using System.Diagnostics.Metrics; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace NIFPGA { public sealed class FPGAWriteProperty : FPGABaseProperty where T : unmanaged { private object lockObject = new object(); internal FPGAWriteProperty(FPGASession session, uint indicator) : base(session, indicator, false) { } private void SetValue(T value) { lock (lockObject) { T oldvalue = GetValue(); if (object.Equals(value, oldvalue)) return; switch (value) { case Boolean boolvalue: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Convert.ToByte(boolvalue))); break; case Byte: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref value))); break; case SByte: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref value))); break; case Int16: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref value))); break; case UInt16: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref value))); break; case Int32: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref value))); break; case UInt32: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref value))); break; case Int64: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref value))); break; case UInt64: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref value))); break; case Single: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref value))); break; case double: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, Unsafe.As(ref value))); break; } } } private T GetValue() { lock (lockObject) { T value = default; switch (value) { case Boolean: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, ref Unsafe.As(ref value))); break; case Byte: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, ref Unsafe.As(ref value))); break; case SByte: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, ref Unsafe.As(ref value))); break; case Int16: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, ref Unsafe.As(ref value))); break; case UInt16: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, ref Unsafe.As(ref value))); break; case Int32: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, ref Unsafe.As(ref value))); break; case UInt32: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, ref Unsafe.As(ref value))); break; case Int64: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, ref Unsafe.As(ref value))); break; case UInt64: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, ref Unsafe.As(ref value))); break; case Single: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, ref Unsafe.As(ref value))); break; case double: _Session.CheckResult(_Session.GetDelegate()(_Session.Session, Indicator, ref Unsafe.As(ref value))); break; } return value; } } public T Value { get => GetValue(); set => SetValue(value); } } }