FPGAArrayFXPWriteProperty.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using FxpConvert.Common;
  2. namespace NIFPGA
  3. {
  4. public sealed class FPGAArrayFXPWriteProperty : FPGABaseProperty
  5. {
  6. Interop.NiFpgaDll_ReadArrayU64 Read;
  7. Interop.NiFpgaDll_WriteArrayU64 Write;
  8. private NiFpga_FxpTypeInfo _TypeInfo;
  9. private IFxpConvert _Convert;
  10. private ulong[] tempvalue = new ulong[0];
  11. private float[] doubles = new float[0];
  12. internal FPGAArrayFXPWriteProperty(FPGASession session, uint indicator, uint count,NiFpga_FxpTypeInfo typeInfo, IFxpConvert convert) : base(session, indicator,false)
  13. {
  14. _Convert = convert;
  15. Count = count;
  16. tempvalue = new ulong[count];
  17. doubles = new float[count];
  18. _TypeInfo = typeInfo;
  19. Read = _Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU64>();
  20. Write = _Session.GetDelegate<Interop.NiFpgaDll_WriteArrayU64>();
  21. }
  22. private float[] GetData()
  23. {
  24. _Session.CheckResult(Read(_Session.Session, Indicator, ref tempvalue[0], Count));
  25. _Convert.FxpConvertToFloat(ref tempvalue[0], _TypeInfo, ref doubles[0], Count);
  26. return doubles;
  27. }
  28. private void SetData(float[] values)
  29. {
  30. if (values.Length != Count) return;
  31. _Convert.FloatConvertToDxp(ref values[0], _TypeInfo, ref tempvalue[0], Count);
  32. _Session.CheckResult(Write(_Session.Session,Indicator, ref tempvalue[0], Count));
  33. }
  34. public uint Count { get; }
  35. public float[] Value { get => GetData(); set => SetData(value); }
  36. }
  37. }