![](https://pdfstore-manualsonline.prod.a.ki/pdfasset/c/de/cdec7def-b4a8-4ada-8bb2-177ce8d54e6c/cdec7def-b4a8-4ada-8bb2-177ce8d54e6c-bg46.png)
Project 06/2005 Danaher Motion
60 Rev E M-SS-005-03l
3. 5 EVENT HANDLER
The main program can contain sections which automatically handle events.
This reduces the programming effort required to make tasks respond quickly
and easily to realtime events. Event handlers begin with OnEvent and end
with End OnEvent and occur just after the Program keyword.
After OnEvent is loaded, turn the event On with EventOn just after the End
OnEvent keyword (enable immediately). However, you can enable and
disable OnEvent at any time using EventOn and EventOff. Multiple
OnEvents can be written sequentially. The MC system can support up to 64
events. The number of OnEvent(s) in a single task is not restricted, so a task
may have from 0 to 64 OnEvent(s).
It is important to understand that OnEvents are different from ordinary tasks.
OnEvents are preemptive within the task. That is, an OnEvent runs until
complete and the program execution returns to the main program. While an
OnEvent is executing, it does not release CPU time to the parent task or any
other task. In this sense, OnEvents are similar to interrupt calls. They run to
completion before execution returns to the main program. An OnEvent must
have a higher priority than its parent task to ensure that when an event
occurs, it interrupts its parent task and runs to completion. The rules are valid
for a single process, (that is, the parent task and its events), while events of
the respective tasks in the system share the CPU among themselves.
3.5.1. OnEvent
The syntax of OnEvent is:
OnEvent [EventName] [Condition] {Priority=EventPriority}{ScanTime=time}
where
EventName is any legal name that is otherwise not used in the
task.
Condition is any logical expression such as System.Dout.1 = 1.
The event fires on transitions of the condition from false
to true.
Priority is an integer from 1 (highest) to 16 (lowest). If not entered,
priority defaults to 1. The priority should always be
higher than the priority of the task or the event never
runs.
Time is an integer indicating the number of cycles between each
scan. Time defaults to 1.
In this example, an event is set up to move axis "X-axis" to 10000 counts
each time an input goes high:
OnEvent MOVE_ON_TRIGGER System.Din.1=ON
Move X-axis 10000
End OnEvent
Normally, event handlers run at a high priority so that once the event occurs,
they run to completion. In most cases, this code should be very short as it
usually takes all resources until it is complete.
ScanTime is in cycles of the SERCOS update rate. This is normally 2 or 4
milliseconds. Setting ScanTime to 5 configures the system to check the
event condition every 10 or 20 milliseconds, depending on your update rate.
For example:
OnEvent System.Din.2 = ON ScanTime = 5