Trap Statement (System status trigger)

Defines interrupts and what should happen when they occur.

With the Trap statement, you can jump to labels or call functions when the event occurs. Trap statement has 2 types as below:

  • 4 Traps that interrupts by the user defined input status
  • 7 Traps that interrupts by the system status

Trap with system status triggers is explained here.

Syntax
Trap {Emergency | Error | Pause | SGOpen | SGClose | Abort | Finish }​ Xqt funcname

Trap {Emergency | Error | Pause | SGOpen | SGClose | Abort | Finish }​

Parameters

Emergency
The specified function is executed in the emergency stop status.
Error
The specified function is executed in the error status.
Pause
The specified function is executed in the pause status.
SGOpen
The specified function is executed when safeguard is open.
SGClose
The specified function is executed when safeguard is closed.
Abort
The specified function is executed when all tasks except the background tasks stop (such as when a statement corresponding to the Abort All is executed or Pause button is pressed) by the user or system.
Finish
The specified function is executed when all tasks except the background tasks are completed. It cannot be executed in the condition which executes the Trap Abort.
funcname
Function of interrupt processing task for which Xqt is executed when the system status is completed. The function with argument cannot be specified. However, three parameters can be specified if “Error” is specified for the parameter.

Note


Trap *** Call function of EPSON RC+4.x or before is replaced to Trap *** Xqt in EPSON RC+ 7.0, Epson RC+ 8.0.


Description
When the system status completes, the specified interrupt processing task is executed.

Even if you execute an interrupt processing task, the Trap settings cannot be cleared.

To clear the Trap setting, omit the funcname and execute the Trap statement.

Example: Trap Emergency clears Trap Emergency

After all normal tasks are completed and the controller is in the Ready status, all Trap settings are cleared.

You cannot execute more tasks using the Xqt from an interrupt processing.

CAUTION

  • Forced Flag

    You can turn On/Off the I/O outputs even in the Emergency Stop status, Safeguard Open status, Teach mode, or error status by specifying the Forced flag to the I/O output statement such as On and Off statements.

    DO NOT connect the external devices which can move machines such as actuators with the I/O outputs which specifies the Forced flag. It is extremely dangerous and it can lead the external devices to move in the Emergency Stop status, Safeguard Open status, Teach mode, or error status.

    I/O outputs which specifies the Forced flag is supposed to be connected with the external device such as LED as the status display which cannot move machines.

  • If Emergency is specified

    When the Emergency Stop is activated, the specified function is executed in the NoEmgAbort task attribute.

The commands executable from the interrupt processing tasks can execute the NoEmgAbort task.

When the interrupt processing of Emergency Stop is completed, finish the task promptly. Otherwise, the controller cannot be in the Ready status. You cannot reset the Emergency Stop automatically by executing the Reset command from the interrupt processing task.

When the task executes I/O On/Off from the interrupt processing task, uncheck the [Outputs off during emergency stop] check box in the [Controller]-[Preferences] page. If this check box is checked, the execution order of turn Off by the controller and turn On using the task are not guaranteed.

  • If Error is specified

    When the Error is activated, the specified function is executed in the NoEmgAbort task attribute.

The commands executable from the interrupt processing tasks can execute the NoEmgAbort task.

When the interrupt processing of Emergency Stop is completed, finish the task promptly. Otherwise, the controller cannot be in the Ready status.

The three omittable parameters (errNumber, robotNumber, jointNumber) can be specified to the user function. If you want to use these parameters, add three byval integer parameters to the trap function.

If a motion error occurs, errNumber, robotNumber, and jointNumber are set.

If an error other than the motion error occurs, ’0’ will be set to robotNumber, and jointNumber.

  • If Pause is specified

    When the Pause is activated, the specified function is executed in the NoEmgAbort task attribute.

  • If SGOpen is specified

    When the Safeguard is open, the specified function is executed in the NoEmgAbort task attribute.

  • If SGClose is specified

    When the safeguard is closed and latched, the specified function is executed in the NoEmgAbort task attribute.

If you execute the Cont statement from the interrupt processing tasks, an error occurs.

  • If Abort is specified

    All tasks except background tasks stop (such as when a statement corresponding to the Abort All is executed or Pause button is pressed) by the user or system, executes the specified function in the NoPause attribute.

When the interrupt processing of Pause is completed, finish the task promptly. Otherwise, the controller cannot be in the Ready status.

Although a task executed with the Trap Abort has an error, the Trap Error processing task is not executed.

If the Shutdown or Restart statements are aborted, processing tasks of neither the Trap Abort nor Trap Finish is executed.

  • If Finish is specified

    All tasks except the background tasks stops (such as when a statement corresponding to the Abort All is executed or Pause button is pressed) by the user or system, executes the specified function in the NoPause attribution. It cannot be executed in the condition which executes the Trap Abort processing task.

When the shutdown and interrupt processing are completed, finish the tasks promptly. Otherwise, the controller cannot be in the Ready status.

See Also
Era, Erl, Err, Ert, ErrMsg$, OnErr, Reset, Restart, SysErr, Xqt

Trap Statement Example

Function main
    :
  Trap Error Xqt suberr
    :
Fend

Function suberr
  Print "Error =", Err
  On ErrorSwitch
Fend

Function main

  Trap Error Xqt trapError

FEnd


Function trapError(errNum As Integer, robotNum As Integer, jointNum As Integer)
Print "error number = ", errNum
Print "robot number = ", robotNum
Print "joint number = ", jointNum
If Ert = 0 Then
  Print "system error"
Else
  Print "task error"
  Print "function = ", Erf$(Ert)
  Print "line number = ", Erl(Ert)
EndIf
FEnd