{-------------------------------------------------------------------------------
 STEP        : IP_GetValue.IPS
 PROJECT     :
 DESCRIPTION : Get a value
 RESULT      : 0 = success
 PROGRAMMER  : 2011-03-01 / gt /MCD
 UPDATE      :
-------------------------------------------------------------------------------}
parameter
  prWaitBefore  : ( 1, real,   'Wait before',               '0..60000', '0' );  // Delay before measurement in ms
  psName1       : ( 2, string, 'Value 1 name',              ''              );  // Value name
  psName2       : ( 3, string, 'Value 2 name',              ''              );  // Value name
  prFactor      : ( 4, real,   'Factor (0=none)',           ''        , '0' );  // A factor to adjust the value
  prDB          : ( 5, real,   'DB (0=none, 1=dBV, 2=dBu)', ''        , '0' );  // Convert to DB (0=none, 1=dBV, 2=dBu)
  prSampleRate  : ( 6, real,   'Sample rate',               ''              );  // Sample rate
  psAttributes1 : ( 7, string, 'Attributes 1',              ''              );  // Attributes
  psAttributes2 : ( 8, string, 'Attributes 2',              ''              );  // Attributes
  prWaitAfter   : ( 9, real,   'Wait after',                '0..60000', '0' );  // Delay after measurement in ms

var
  vrActiveDuts : vector;
  vrIndex : real;
  vCurve1 : vector;
  vCurve2 : vector;

uses
  'LIB_ToolManager';

step

  DateTime.Delay(prWaitBefore, true);

  Action.Trigger(2020);

  vrActiveDuts := ActiveDuts;
  for vrIndex := 1 to Len(vrActiveDuts) do begin

    TM_SetAttributes(psName1, psAttributes1);

    if psName2 <> '' then begin
      TM_SetAttributes(psName2, psAttributes2);
    end;

    
    repeat

      vCurve1 := TM_GetStream(psName1, prFactor, prDB);

      if psName2 <> '' then begin
        vCurve2 := TM_GetStream(psName2, prFactor, prDB);
      end;

      SetLen(vCurve1,250);
      SetLen(vCurve2,250);

      if psName2 = '' then begin
        Curve.Setup(1, prSampleRate, vCurve1);
        Curve.Name(1, psName1);
      end else begin
        Curve.Setup(1, prSampleRate, vCurve1, vCurve2);
        Curve.Name(1, psName1, psName2);
      end;

      SetValueEx (vrActiveDuts[vrIndex], 0);

      if not stepcontinue then begin
        DateTime.Delay(50, true);
      end;

    until stepcontinue;
    
    DateTime.Delay(prWaitAfter, true);
    DateTime.Delay(Math.Random * Val(RegForm.Get('RFE_STEPDELAY'),0), true);

  end;

end.

