Tutorial
PL/i Programming Language for i.CanDoIt
This set of pages will provide brief tutorials about programming in PL/i. This language is more simple than C, but more structured than Basic. The objective in creating this language was to compile compact code that would run efficiently and safely as a virtual machine, like a very lean Java.
Index of PL/i Tutorials
Tutorial #8

Connecting PL/i Programs to the Scheduler

We are going to use a very simple example of connecting a program to the scheduler. This example would not require a program at all. We are simply doing the scheduled action this way for illustration. Normally, to do something simple like turn an output on and off according to a schedule, you would simply set up the schedule entry shown above, and see that the register number was associated with the desired output. But the register number can also be treated as input to your program, thus causing the program to do something according to a schedule. The following example illustrates this.

program onSchedule
declare

begin
while TRUE do
begin
select
when geti(44) = 1 seti(25, 1);
otherwise seti(25, 0);
end;
delay(50);
end;
end

This example will (indefinitely) check the register set by the schedule, and turn on a relay when "on". The relay in this case will come on at 8:00AM and go off at 5:00PM every weekday.

The above example of scheduling is overly simplistic. In a real application, you would most likely define a couple of procedures that did some combination of complex things. The select statement would be more likely to look like this:

select
when geti(44) = 1 do_my_daily_thing();
otherwise do_my_afterhours();
end;

Suppose you want to schedule a procedure to be called only once a day at 8:00 AM using the above schedule. You would include the following somewhere in your endless loop:

if geti(44) = 1 then
begin
do_this_once();
seti (44, 0);
end;
end;

The scheduler will only set the register once at the transition time in the schedule. You may reset it to result in doing something only once assuming the register is only used as a flag between the scheduler and the program. Note also that if power is lost, the scheduler will "resume" upon power-up and the register will be set once again.

Connecting PL/i Programs to Other Server Features

This of course assumes that you are using a product that includes the i.CanDoIt server. Anything that can be triggered by a level in a register can be triggered by your program. You can trigger SNMP traps, event logs, and email notifications from your program. You can generate data to be logged to the log file.

Interfacing your program to any of these features is easy. Simply decide what your algorithm is for making a decision, decide what data you will generate as a result, pick a place to put it. Next, select that register in the applicable server template, and set the threshold or other parameters as applicable to get the desired action.