dpWaitForValue()

The function waits for a certain time (timeout) for a value change that fulfills the condition and returns the values of the different or same data points via the parameter returnValues.

Synopsis

int dpWaitForValue( dyn_string dpNamesWait, dyn_anytype conditions, dyn_string dpNamesReturn, dyn_anytype &returnValues, time timeout [,bool &timerExpired]);

Parameters

Parameter Meaning
dpNamesWait List of DPs which are compared to the conditions values.
conditions (desired) values of any type and number, that must match the value types of dpNamesWait. The function waits for value changes which meet the conditions.
dpNamesReturn DP list with the values to return. dpNamesWait and dpNamesReturn may contain the same DPs.
returnValues Value which is returned from the list dpNamesReturn (with dpSet()).
timeout time interval that defines how long the function waits for a value that meets the conditions. A timeout of 0 stops the function from timing out.
timeExpired optional parameter that is set TRUE if the function has timed out.

Return Value

In the event of an error -1, otherwise 0

Errors

Errors can be retrieved with getLastError(). An error message is issued in the event of missing or incorrect arguments.

Description

The function waits for a certain time (timeout) for a value change that fulfills the condition and returns the values of dpNamesReturn via the parameter returnValues. If the timeout expires, returnValues are not affected. The function allows a type of dpConnect() to several data points at the same time. This means that limited queries of data point values are possible, or if no condition is set, the values of other DPEs are returned if changes are made to dpNamesWait.

Note that the function cannot be executed if the condition is already fulfilled when calling the function and no value change occurs on any of the named data point elements. Thus, the function waits for an value change that fulfills the condition.

Example

A child panel is to be opened, then the program waits for 5 seconds to see whether the value fulfills the condition "child.pnl" (either OK or cancel). The child panel contains buttons which set values when you click them. If this value is "child.pnl" (either OK or cancel), the condition is fulfilled. The data point that sets the value and the associated value are returned.

main()
{
  time t;
  dyn_string dpNamesWait, dpNamesReturn;
  dyn_anytype conditions, returnValues;
  int status;
  // assignment of the data points for dpNamesWait
  dpNamesWait =
  makeDynString("_PanelOff.PanelName:_original.._value");
  // indication of the condition that must be fulfilled
  conditions[1] = "child.pnl";
  // assignment of the data points for dpNamesReturn (data
  points
  // of the child panel that is parameterised for buttons
  dpNamesReturn = makeDynString(
  "_PanelOff.PanelName:_original.._value" );
  // timeout
  t = 5;
  // The child panel is opened
  ChildPanelOn( "child.pnl", "child", "", 0, 0 );
  // The function is called
  status = dpWaitForValue( dpNamesWait, conditions, dpNamesReturn,
  returnValues, t );
  // Clears the value of the DP
  dpSet( "System1:_PanelOff.PanelName:_original.._value","" );
  if ( status == -1 )
  {
    DebugN( "Error" );
    DebugN( "dpNamesWait : " + dpNamesWait );
    DebugN( "conditions : " + conditions );
    DebugN( "dpNamesReturn : " + dpNamesReturn );
    DebugN( "returnValues : " + returnValues );
  }
  else if ( dynlen(getLastError()) != 0 )
  {
    DebugN( "Error returned in message" );
    // Reaction: , for example, output
    DebugN( getLastError() );
    DebugN( "dpNamesWait : " + dpNamesWait );
    DebugN( "conditions : " + conditions );
    DebugN( "dpNamesReturn : " + dpNamesReturn );
    DebugN( "returnValues : " + returnValues );
  }
  else
  {
    DebugN( "everything ok" );
    DebugN( "dpNamesWait : " + dpNamesWait );
    DebugN( "conditions : " + conditions );
    DebugN( "dpNamesReturn : " + dpNamesReturn );
    DebugN( "returnValues : " + returnValues );
  }
}

Assignment

Data point function, waiting Control function

Availability

CTRL