Promotic

AddEventTimer - method of the PmgRoot object

Description:
Registers a function into the panel inner timer for unrepeated or repeated calling after a defined time period.
Syntax:
Empty AddEventTimer(Long nTime, Long nType, String sFuncId, Function Func)
Parameters:
nTime(Long) Either a time period (period or timeout) in milliseconds, after which the function is called
or date and time (Date data type) when the function is called.
nType(Long) Inner timer request type.
0 - (or -1 obsolete) The function will be called repeatedly with defined period.
1 - The function will be called once with defined delay (timeout).
2 - The function will be called once with the specified date and time. This method is not functional in Web panels.
sFuncId(String) Identifier of registered event function.
- Allows removal of function by the RemoveEventTimer method.
- Prevents duplicate registering of the same function.
- May contain any characters (this is not a system name).
- Must not be an empty string.
- It is recommended to use e.g. the whole path to Pmg object.
Func(Function) JavaScript event function that will be called by panel timer.
Note:
The inner panel timer allows to create panel animations (periodical calling), watch passing of defined time period of some asynchronous event (timeout), or react to some events with delay. All these features are not in any way dependent on the refresh rate of the panel.
This method is also functional in Web panels.
See also:
Example:
The example of repeated (10x) running of the event function executed in two ways. The first approach is to repeatedly register new function for single execution while it is needed.
JavaScriptSelect and copy to clipboard

function OnTick()
{
Pm.Debug("OnTick: tClick=" + Pm.FormatDate(tClicked, 1) + ", nCounter=" + nCounter);
if (nCounter-- > 0)
{
pMe.Root.AddEventTimer(1000, 1, pMe.GetPathName(), OnTick);
}
}
var tClicked = Pm.Time;
var nCounter = 10;
pMe.Root.AddEventTimer(1000, 1, pMe.GetPathName(), OnTick);
Another approach is to register the event function once for repeated execution and then unregistering it after it is no longer needed. Simultaneously executes animation of object "Ellipse" in the panel.
JavaScriptSelect and copy to clipboard

function OnTick()
{
Pm.Debug("OnTick: tClick=" + Pm.FormatDate(tClicked, 1) + ", nCounter=" + nCounter);
oObject.X += 5;
oObject.Refresh();
if (nCounter-- < 0)
{
pMe.Root.RemoveEventTimer(pMe.GetPathName(), OnTick);
}
}
var tClicked = Pm.Time;
var nCounter = 10;
var oObject = pMe.Items("/Ellipse");
pMe.Root.AddEventTimer(60, 0, pMe.GetPathName(), OnTick);

History:
Pm9.00.25: New option 2 in the nType parameter
Pm9.00.16: New the sFuncId parameter
Pm9.00.06: Created
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.