Click or drag to resize

TaskCancelRoutine Method

Cancels any current execution of a routine called with CallRoutine(String, RegainMode) and restores the execution stack.

Namespace:  ABB.Robotics.Controllers.RapidDomain
Assembly:  ABB.Robotics.Controllers (in ABB.Robotics.Controllers.dll) Version: 6.5.129.0
Syntax
C#
public void CancelRoutine()
Remarks
If no routine is currently executing, the call will be ignored.
Examples
In this example an event handler checks whether execution has stopped inside a routine executed at user level (a service routine). If so, a "Cancel Routine" button is displayed, which allows the operator to cancel the execution at user level (and then be able to return to normal execution). (The start button of the FlexPendant allows him to restart the service routine if this is what is desired.)

If the "Cancel Routine" button is pressed the CallRoutine(String) request is canceled, restoring the program pointer to its location outside of the routine.

using ABB.Robotics;
using ABB.Robotics.Controllers;
using ABB.Robotics.Controllers.RapidDomain;
...
Controller c = new Controller();
Task[] allTasks = c.Rapid.GetTasks();
Task tRob1 = allTasks[0];
...

// this is the event handler of the subscription set up when CallRoutine was called
void tRob1_ExecutionStateChanged(object sender, ExecutionStateChangedEventArgs e)
{
  try
  {
    //check if execution has been stopped in a routine started by CallRoutine
    if (tRob1.ExecutionState == ExecutionState.Stopped && tRob1.ExecutionType == ExecutionType.UserRoutine)
    {
      //Invoke to force execution to the GUI thread
      this.Invoke(new EventHandler(UpdateGUI), sender, e);
    }
  }
  catch (System.Exception)
  {
    // Exception handling
    ...
  }
}

private void UpdateGUI(object sender, EventArgs e)
{
  try
  {
    btnCancelRout.Visible = true;
    btnStartRout.Visible = false;
  }
  catch (System.Exception ex)
  {
    // Exception handling
    ...
  }
}

private void btnCancelRout_Click(object sender, EventArgs e)
{
  try
  {
    tRob1.CancelRoutine();
    btnCancelRout.Visible = false;
    btnStartRout.Visible = true;
  }
  catch (System.Exception ex)
  {
    // Exception handling
    ...
  }
}
See Also