alertConnect()

Registers the function work() for call with resulting alerts.

Synopsis

int alertConnect([class object,] string|function_ptr work, [bool answer,] string alert1 [, string alert2 ...]|dyn_string alert_list);

Parameters

Parameter Description
object An object of a Control++ class.
work

Name of the work function that is called when alerts occur

Or

a function pointer to the work function (callback function).

answer Determines whether work is run immediately when alertConnect is called (true) or only when the alert attribute has changed ("false"). Default is "true".

alert1, alert2, ...

|

alert_list

Alert handling attributes or a list of alert handling attributes (dyn_string).

Return value

Returns 0, in the event of a failure returns -1.

Errors

Errors can be retrieved with getLastError(). The return value is then the appropriate error code. An alert is issued in the event of non-existent data points, incorrect parameter transfers or spelling errors.

Description

The function alertConnect() registers the function work() for call with resultant alerts for the alert handling attributes alert1, alert2, ... The work function is then processed for every resulting alert or if changes are made to certain registered alert handling attributes (see below). Any number of these attributes may be registered.

In contrast to dpConnect(), alertConnect() does not connect with alert handling attributes of individual data point elements, but rather with the appropriate attributes of all data point elements!

Valid alert handling attributes: see table _alert_hdl.

Work function

When alertConnect() is called, the work function is also executed once with the current values of the data point attributes specified there, provided that the argument answer was not set to "false".

The registered function work() must have the following transfer parameters. Any name may of course be assigned to the work function.

void work(time t, int count, string alert1, <type1> var1 [, string alert2, <type2> var2 ...])

Parameter Description
t Alert time
count Counter for alerts with alert time
alert1, alert2, &ldots; Alert handling attributes
type1, type2 Data type of the alert handling attribute

Whereas no attributes of individual data point elements are transferred to the function alertConnect(), the write function writes the complete attribute addresses to the alert variables! So "valve17.opening:_alert_hdl.._text" and not only ":_alert_hdl.._text"!

main()
{
alertConnect("work",":_alert_hdl.._text",":_alert_hdl.._visible");
}

In the following example a data point list with two data points is passed. The output of the values is done in the callback function.

main()
{
  alertConnect("work", makeDynString(":_alert_hdl.._text", ":_alert_hdl.._visible"));
  delay(2);
  alertDisconnect("work", makeDynString(":_alert_hdl.._text",":_alert_hdl.._visible"));
}
void work(time t, int count, string alert1, string var1, string alert2, bool var2)
{
  DebugN(t, count, alert1, var1, alert2, var2);
}

Assignment

Alert handling, waiting control function

Availability

CTRL