Scheduler Example
The following programming example uses a day timer to illustrate how the blocks should be parameterised, particularly with regard to the inputs eStartEnd, stStartEnd and stSystemTime.
We recommend using the block NT_GetTime, which is available in the library TcUtilities.lib, for reading the system time in PC- and CX-based systems. A program for reading might look as follows:
It provides a time base for parameterizing the scheduler blocks with regard to the time input stSystemTime. The enumerator matching the required behavior is created at input eStartEnd:
eSTARTTIME_ENDTIME |
Start criterion: Time - End criterion: Time |
eSTARTTIME_DURATION |
Start criterion: Time - End criterion: Duration |
eSTARTTIME_ENDEVENT |
Start criterion: Time - End criterion: Event (boolean input) |
eSTARTEVENT_ENDTIME |
Start criterion: Event (boolean input) - End criterion: Time |
eSTARTEVENT_DURATION |
Start criterion: Event (boolean input) - End criterion: Duration |
eSTARTEVENT_ENDEVENT |
Start criterion: Event (boolean input) - End criterion: Event (boolean input) |
For the input stStartEnd a structure variable of the same type has to be declared that is referred to in the example as stStartEnd. In program the subvariables for this structure that are relevant for the function type are described. For the example shown here these are todStartTime and tDuration. All other variables are not read and therefore do not have to be described.
Both programs have to be called in the MAIN block. The program part P_SchedulerExample may only be called once the program part P_SystemTime supplies valid data, i.e. once P_SystemTimeValid is TRUE. The reason for this protective logic is that reading the time takes several cycles which means that the time when the program starts is invalid and must not be used.
If the program starts on 1 January, the sequences is as follows:
The days on which actions are triggered start with the 2nd of the year (uiBegin:=2). The process is repeated every three days (uiPeriodicity:=3). The switch-on time is 15:00 (stStartEnd.todStartTime := tod#15:00:00) and the switching duration is 6 hours (stStartEnd.tDuration := t#6h).