---
title: "Monitor the state of a robot controller"
description: "Follow the operating mode, servo power, program execution and alarm state of Fanuc, Yaskawa, Universal Robots and ABB controllers with one code. C# and Python examples."
---

# Monitor the state of a robot controller

This article shows how to follow the operating mode, the servo power, the program execution and the alarm state of Fanuc, Yaskawa, Universal Robots and ABB controllers from a PC, with one code in C# or Python. The table at the end gives what each brand reads, and what to read instead on a Stäubli controller.

The state of a Stäubli controller is not in the common API: the support table below shows it.

## Prerequisites

- UnderAutomation.Robotics in your project. See [Get started with .NET](/robotics/documentation/get-started-net) or [Get started with Python](/robotics/documentation/get-started-python).
- The connection settings of each controller. See [Connect to your robot](/robotics/documentation/connect).
- The license of each brand you connect, or the 30 day trial. See [Licensing](/robotics/documentation/license).
- Reading the state does not change the controller.

## Brand support

Each cell gives the protocol that the method uses on this brand, in the default order. The table is generated from the route data of the library. "Not available" means that the brand has no route for the method: the call throws `FeatureNotSupportedException`, and `IsAvailable` returns false before the call. (manual) marks a route that you enable yourself in the connection parameters.

Routes of each method in the default order. The first route is used, the next ones are fallbacks. (manual) marks a route that you enable yourself.

| Method | Fanuc | Yaskawa | Universal Robots | ABB | Stäubli |
| --- | --- | --- | --- | --- | --- |
| State.Read | SNPX, FTP | High Speed Ethernet Server, Ethernet Server | Dashboard Server, Primary Interface (Primary) | Robot Web Services | Not available |
| State.ServoOn | CGTP (CgtpKcl), Telnet, SNPX, RMI (manual) | High Speed Ethernet Server, Ethernet Server | Dashboard Server, REST API, Primary Interface (Primary) | Robot Web Services | SOAP |
| State.ServoOff | Not available | High Speed Ethernet Server, Ethernet Server | Dashboard Server, REST API, Primary Interface (Primary) | Robot Web Services | SOAP |
| State | **2 of 3** | **3 of 3** | **3 of 3** | **3 of 3** | **2 of 3** |

## Example

### Follow the controllers of a cell

The example connects to each controller of a cell once, then reads the state of every controller once per second. `Read` returns a `ControllerStateInfo`: `Mode` is the operating mode, `ServoOn` the servo power, `Running` true when a program runs, and `AlarmPresent` true when an alarm is active. Keep the connections open between two reads: a connection takes more time than a read.

**C# : StateAllBrands**
```csharp
using UnderAutomation.Robotics.Controllers;

public class StateAllBrands
{
    static void Main()
    {
        /**/
        // Connect each controller of the cell once: only the brand and the address change
        var cell = new[]
        {
            (Brand: "fanuc", Address: "192.168.0.1"),
            (Brand: "yaskawa", Address: "192.168.0.2"),
            (Brand: "universalrobots", Address: "192.168.0.3"),
            (Brand: "abb", Address: "192.168.125.1"),
        };

        var robots = new List<RobotController>();
        foreach (var controller in cell)
        {
            RobotController robot = new RobotController();
            robot.Connect(RobotConnectionParameters.Create(controller.Brand, controller.Address));
            robots.Add(robot);
        }

        // Read the state of each controller once per second, with the same code for each controller
        for (int i = 0; i < 10; i++)
        {
            foreach (RobotController robot in robots)
            {
                ControllerStateInfo state = robot.State.Read();
                Console.WriteLine($"{robot.Brand}: {state.Mode}, servo on: {state.ServoOn}, running: {state.Running}, alarm: {state.AlarmPresent}");
            }
            Thread.Sleep(1000);
        }

        foreach (RobotController robot in robots)
            robot.Disconnect();
        /**/
    }
}
```

**Python : StateAllBrands**
```python
import time

from underautomation.robotics.controllers.robot_controller import RobotController
from underautomation.robotics.controllers.robot_connection_parameters import RobotConnectionParameters

##
# Connect each controller of the cell once: only the brand and the address change
cell = [
    ("fanuc", "192.168.0.1"),
    ("yaskawa", "192.168.0.2"),
    ("universalrobots", "192.168.0.3"),
    ("abb", "192.168.125.1"),
]

robots = []
for brand, address in cell:
    robot = RobotController()
    robot.connect(RobotConnectionParameters.create(brand, address, ""))
    robots.append(robot)

# Read the state of each controller once per second, with the same code for each controller
for _ in range(10):
    for robot in robots:
        state = robot.state.read()
        print(f"{robot.brand.name}: {state.mode.name}, servo on: {state.servo_on}, running: {state.running}, alarm: {state.alarm_present}")
    time.sleep(1)

for robot in robots:
    robot.disconnect()
##
```

In Python, the names are in snake_case: `robot.state.read()`, `state.servo_on`, `state.alarm_present`, and `state.mode.name` gives the name of the mode.

`Automatic` is the mode where programs run without an operator at the pendant. Some controllers call it play or remote mode. `Manual` is the manual mode at reduced speed, and `ManualFullSpeed` the manual mode at full speed.

### Switch the servo power

`ServoOn` and `ServoOff` switch the motors on and off, on the brands that have them. Ask `IsAvailable` before the call. They return when the controller accepted the command: call `Read` to know when the motors are on.

**C# : StateServo**
```csharp
using UnderAutomation.Robotics.Controllers;

public class StateServo
{
    static void Main()
    {
        RobotController robot = new RobotController();
        robot.Connect(RobotConnectionParameters.Create("fanuc", "192.168.0.1"));

        /**/
        // ServoOff is not supported by every brand: ask before calling
        if (robot.State.IsAvailable(StateFeature.ServoOff))
        {
            robot.State.ServoOff();
        }

        robot.State.ServoOn();
        /**/

        robot.Disconnect();
    }
}
```

**Python : StateServo**
```python
from underautomation.robotics.controllers.robot_controller import RobotController
from underautomation.robotics.controllers.robot_connection_parameters import RobotConnectionParameters
from underautomation.robotics.controllers.state_feature import StateFeature

robot = RobotController()
robot.connect(RobotConnectionParameters.create("fanuc", "192.168.0.1", ""))

##
# servo_off is not supported by every brand: ask before calling
if robot.state.is_available(StateFeature.ServoOff):
    robot.state.servo_off()

robot.state.servo_on()
##

robot.disconnect()
```

## What changes from one brand to another

The code does not change. Each controller gives its state in its own way.

| Brand | Read | Servo power | Brand article |
| --- | --- | --- | --- |
| Fanuc | The mode is the one of the last mode change in the alarm history. It is `Unknown` when this change is no longer in the history. | `ServoOn` resets the controller: the servo power comes back when the safety chain is closed, and the alarms that can be cleared are cleared. No `ServoOff`. | [Monitor the task execution](/fanuc/documentation/monitor-task-execution) |
| Yaskawa | The teach mode gives `Manual`, the play mode gives `Automatic`. | `ServoOn` and `ServoOff` need the remote mode. | [Monitor the state](/yaskawa/documentation/how-to-monitor-state) |
| Universal Robots | The robot mode of the controller and the state of its program. | `ServoOn` powers the robot on and releases the brakes. On e-Series and PolyScope X, the robot is in remote control. | [Monitor the state](/universal-robots/documentation/how-to-monitor-state) |
| ABB | Controller state (motors), operation mode and execution of RAPID. | `ServoOn` and `ServoOff` switch the motors on and off. | [Controller](/abb/documentation/rws-controller) |
| Stäubli | Not available. Read the execution of the programs with `robot.Program.ReadExecution()` and the position with `robot.Motion.ReadPose()`. | `ServoOn` and `ServoOff` need the remote mode. | [Monitor the state](/staubli/documentation/how-to-monitor-state) |

## Errors

- `FeatureNotSupportedException`: the brand has no route for the method, for example `Read` on Stäubli or `ServoOff` on Fanuc.
- `RouteUnavailableException`: the method has routes, but none can be used, for example because the protocol did not answer at the connection.
- `ControllerRefusedException`: the controller received `ServoOn` or `ServoOff` and refused it, for example because it is not in remote mode.
- `RobotControllerException`: the route failed. Its inner exception is the exception of the brand SDK.

The page [Errors](/robotics/documentation/errors) explains each exception.

## What to read next

- [State](/robotics/documentation/state): the `ControllerStateInfo` type.
- [Read and reset robot alarms](/robotics/documentation/how-to-read-reset-alarms): read the alarms when `AlarmPresent` is true.
- [Get the current position of a robot](/robotics/documentation/how-to-get-position): the position of the same controllers.