dpSetAndWaitForValue()
This function is a combination of the functions dpSet() and dpWaitForValue().
Synopsis
int dpSetAndWaitForValue(dyn_string dpNamesSet, dyn_anytype
dpValuesSet,
dyn_string dpNamesWait, dyn_anytype conditions, dyn_string dpNamesReturn,
dyn_anytype &returnValues, time timeout [,bool
&timeExpired]);
Parameters
| Parameter | Description |
|---|---|
| dpNamesSet | The datapoint attribute a value is assigned to. |
| dpValuesSet | The value that is assigned to the datapoint attribute. |
| dpNamesWait | A datapoint list that is compared to the values of conditions. |
| conditions | Target values of arbitrary type and number. The values must correspond to the dp list dpNamesWait. The function waits for a value change that fulfills the conditions. |
| dpNamesReturn | DP list whose values are returned. dpNamesWait and dpNamesReturn can contain same DPs. |
| returnValues | Values that are returned from the list dpNamesReturn via dpSet(). |
| timeout | A time interval that specifies how long the function waits for the conditions to be fulfilled. The value 0 means that the function never expires. |
| timeExpired | Optional parameter that is set to TRUE when the function expires (see timeout above). |
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 triggers a verify function and subsequently sets values according to the dpSet function. The function returns back like the function dpWaitForValue() first when either the condition is fulfilled (this can be fulfilled via the dpSet functionality directly or indirectly) or when the timeout expires.
Set and wait for a value
main()
{
dyn_anytype returnValues;
bool bExpired = 0;
int iTimeOut = 10;
// Datapoint element for which a value is set
dyn_string dpNamesSet = makeDynString("ExampleDP_Arg1.:_original.._value");
// Value to set
dyn_anytype dpValuesSet = makeDynFloat(123);
// Target values for dpNamesWait
dyn_anytype conditions = makeDynFloat(123);
// DP elements to wait for values
dyn_string dpNamesWait = makeDynString("ExampleDP_Arg2.:_online.._value");
// DP elements returned when conditions for dpNamesWait are fulfilled
dyn_string dpNamesReturn = makeDynString("ExampleDP_Arg2.:_online.._value");
// Helper function to simulate a value changes when dpNamesSet are written
DebugTN("call dpConnect");
dpConnect("work", false, "ExampleDP_Arg1.");
// Call function to write values and to wait for conditions
DebugTN("dpSetAndWaitForValue call with timeout " + iTimeOut + " seconds");
dpSetAndWaitForValue(dpNamesSet, dpValuesSet, dpNamesWait, conditions, dpNamesReturn, returnValues, iTimeOut, bExpired);
// Check the result
if (bExpired)
DebugTN("Timeout of " + iTimeOut + " seconds expired - no returnValues");
else
DebugTN("Conditions are met - returnValues received", returnValues);
}
// Work function to simulate a value changes for dpNamesWait
void work(string dp, float value)
{
DebugTN("Entering work function - wait 5 seconds");
delay(5);
DebugTN("Work function, dpSet:ExampleDP_Arg2. = " + value);
dpSet("ExampleDP_Arg2.", value);
}
Assignment
Datapoint function, waiting Control function
Availability
CTRL
