using FxpConvert.Common; namespace NIFPGA { public sealed class FPGAArrayFXPReadProperty : FPGABaseProperty { Interop.NiFpgaDll_ReadArrayU8 Read; private NiFpga_FxpTypeInfo _TypeInfo; private IFxpConvert _Convert; private byte[] tempbuffer = new byte[0]; private ulong[] tempvalue = new ulong[0]; private double[] doubles = new double[0]; internal FPGAArrayFXPReadProperty(FPGASession session, uint indicator, uint count, NiFpga_FxpTypeInfo typeInfo, IFxpConvert convert) : base(session, indicator, true) { _Convert = convert; Count = count; tempvalue = new ulong[count]; doubles = new double[count]; _TypeInfo = typeInfo; tempbuffer = new byte[(int)Math.Ceiling(typeInfo.wordLength * count / 8.0)]; Read = _Session.GetDelegate(); } private double[] GetData() { _Session.CheckResult(Read(_Session.Session, Indicator, ref tempbuffer[0], (uint)tempbuffer.Length)); string s = string.Empty; for (int i = 0; i < tempbuffer.Length; i++) { s += tempbuffer[i].ToString("b").PadLeft(8, '0'); } for (int i = 0; i < tempvalue.Length; i++) { tempvalue[i] = System.Convert.ToUInt64(s.Substring(i * _TypeInfo.wordLength, _TypeInfo.wordLength), 2); } _Convert.FxpConvertToDouble(ref tempvalue[0], _TypeInfo, ref doubles[0], Count); return doubles; } public uint Count { get; } public double[] Value { get => GetData(); } } }