Basics of CAPL-----Timer operation in CAPL

Foreword: When using CPAL, you often want to send periodic messages. In this case, you need a timer to complete the sending of periodic messages. Regarding the sending of messages, there will be an introduction in the following chapters. This chapter mainly explains the operation of the timer.

 

1: Type of timer.

There are two types of timers in CAPL: one is a timer in seconds, and the other is a timer in milliseconds.

2. First you need to define the timer variable in Variables, such as:

After defining the timer variable, you need to define the processing function of the timer.

On timer timer {

}

As shown below

After defining the timer variable, you must also define the timer period, that is, how often the timer processing function is triggered.

Generally, the definition of the timer period needs to be defined when CAPL is started. Of course, it can also be defined again when the timer needs to be started. Here we take startup definition as an example.

Things to be processed when CAPL starts can be handled in on start, as shown below

Setting the timer period requires calling SetTimer, which is the same for millisecond timers and second-level timers. But the parameters set represent milliseconds and seconds respectively.

The implementation allows the timer to be incremented by 1 every cycle, and two Variables are defined to record the number of times the timer processing function is called.

Add the processing function as follows:

Run CanOE and observe in the Write window

It can be found that the timer is only executed once. Each time SetTimer defines a timer period in CAPL, it will only execute the corresponding processing function once. Therefore, if you want to continuously execute the timer processing function, you need to call SetTimer again in the timer processing function, as shown below:

After modification, run CANOE and you can see that every time the millisecond timer is executed 5 times, the second-level timer is executed once.

Guess you like

Origin blog.csdn.net/WlzSnail/article/details/129165004