clockStart (Function)

Top  Previous  Next

Architecture:

NX32L

Firmware version:

1.80.00


This function can be used to install callback functions that are called periodically.

 

Input:

no : INT (0 .. 9)

The index of the timer to configure.

 

freq : INT

The interval between each call of the callback function in seconds. Use 0 to disable the timer.

 

func : CALLBACK

The callback function to call.

 

arg : DINT

A user defined argument that will be passed on to the callback function.

 

 

Returns:

0


- Success

-1


- Invalid parameter.

 

Declaration:

FUNCTION clockStart : INT;
VAR_INPUT
   no     : INT;  // Timer index from 0..9
   freq   : INT;  // Timer interval in seconds. Set to 0 to stop clock.
   func   : CALLBACK;  // callback function with the following parameters: no:int, arg:dint
   arg    : DINT;  // argument
END_VAR;

 

Callback declaration:

FUNCTION CALLBACK clockStartCallback;
VAR_INPUT
   no      : INT;  // Timer index.
   arg     : DINT// User defined argument.
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
// Callback function
FUNCTION CALLBACK myTimer;
VAR_INPUT
   no  : INT;
   arg : DINT;
END_VAR;
   DebugFmt(message:="Timer#\1,arg=\4",v1:=no,v4:=arg);
END_FUNCTION;
 
PROGRAM test;
   // Install timers
   clockStart(no:=0,freq:=2,func:=@myTimer,arg:=2);
   clockStart(no:=1,freq:=5,func:=@myTimer,arg:=5);
   clockStart(no:=2,freq:=10,func:=@myTimer,arg:=10);
   
   WHILE TRUE DO
      Sleep(delay:=1000);
   END_WHILE;
END_PROGRAM;