Using Traps
Traps enable a program to jump to a label or enable a function to be called when a certain event occurs.
Traps are divided into the following two types:
- 4 Traps are fired by user defined input
- 7 Traps are fired by system
You should keep trap functions short and avoid continuous loops. According to the type, some Traps must be re-armed. Also, some motion commands are limited to execute in trap functions.
For details on Trap commands, refer to the following manual:
"SPEL+ Language Reference"
Here is a simple example for a trap. In this example, when input 1 turns on, it executes the Sw1Trap function.
Function main
' Sets the trap
Trap 1 Sw(1) = On Xqt Sw1Trap
Do
RunCycle
Loop
Fend
Function Sw1Trap
' Turn on output 1 for 2 seconds
On 1, 2
' Wait for trap condition to clear
Wait Sw(1) = Off
' Re-arm the trap
Trap 1 Sw(1) = On Xqt Sw1Trap
Fend
Trap | Description |
---|---|
Trap 1 - 4 Goto | Triggered by an input condition specified by the user. User traps can use GoTo, Call, or Xqt. |
Trap 1 - 4 Call | |
Trap 1 - 4 Xqt | |
Trap Emergency Xqt | When Emergency Stop occurs, a specified function is executed. |
Trap Error Xqt | When an error occurs, a specified function is executed. |
Trap SgOpen Xqt | When the Safeguard circuit is open, a specified function is executed. |
Trap SgClose Xqt | When the Safeguard circuit is closed, a specified function is executed. |
Trap Pause Xqt | When the system enters the Pause state, a specified function is executed. |
Trap Abort Xqt | When all tasks (except background tasks) have been stopped by user or system, such as when a command corresponding to Abort All is executed, a specified function is executed. |
Trap Finish Xqt | When all tasks (except background tasks) have been finished, a specified function is executed. However, the function will not be executed under the condition that executes Trap Abort. |