This article shows how to start a job of a Yaskawa Motoman controller from a PC, in C# or Python, and wait for its end. It gives a complete program that checks the mode, resets an alarm, selects the job, switches the servo on and starts it.

## Prerequisites

- The SDK is connected to the controller: see [Connect to your robot](/yaskawa/documentation/connect).
- The controller is in play mode and accepts the remote commands, and the job selection is permitted: see [Prepare the controller](/yaskawa/documentation/connect#prepare_the_controller).
- The job exists on the controller. To send it from the PC, see [Transfer files and backups](/yaskawa/documentation/how-to-transfer-files).

## Steps

| Step                        | Method                                                           |
| --------------------------- | ---------------------------------------------------------------- |
| Check the mode              | `GetStatusInformation()`: `Play`, `CommandRemote`                |
| Reset an alarm              | `AlarmReset(AlarmResetType.Reset)`                               |
| Select the job and its line | `SelectJob(name, line)`                                          |
| One cycle or continuous     | `SwitchingCommand(SwitchingCommands.Cycle)`                      |
| Servo on                    | `ServoCommand(OnOffCommandType.Servo, true)`                     |
| Start                       | `StartJob()`                                                     |
| Follow                      | `GetExecutingJobInformation()`, `GetStatusInformation().Running` |

## Example

**C# : HowToRunProgram**
```csharp
using UnderAutomation.Yaskawa;
using UnderAutomation.Yaskawa.HighSpeedEServer;

public class HowToRunProgram
{
    static void Main()
    {
        /**/
        var robot = new YaskawaRobot();
        robot.Connect("192.168.0.1");

        // 1. Check the mode: play and remote
        RobotStatusData status = robot.HighSpeedEServer.GetStatusInformation();
        if (!status.Play || !status.CommandRemote)
            throw new InvalidOperationException("Set the controller in play mode and remote mode");

        // 2. Reset a pending alarm
        if (status.Alarming)
            robot.HighSpeedEServer.AlarmReset(AlarmResetType.Reset);

        // 3. Select the job at its first line, one cycle, servo on, start
        robot.HighSpeedEServer.SelectJob("WELD01", 0);
        robot.HighSpeedEServer.SwitchingCommand(SwitchingCommands.Cycle);
        robot.HighSpeedEServer.ServoCommand(OnOffCommandType.Servo, true);
        robot.HighSpeedEServer.StartJob();

        // 4. Wait for the end of the job
        do
        {
            Thread.Sleep(200);
            RobotJobData job = robot.HighSpeedEServer.GetExecutingJobInformation();
            Console.WriteLine($"{job.Name} line {job.Line}");
            status = robot.HighSpeedEServer.GetStatusInformation();
        }
        while (status.Running);

        Console.WriteLine(status.Alarming ? "Stopped on an alarm" : "Job done");

        robot.Disconnect();
        /**/
    }
}
```

**Python : HowToRunProgram**
```python
import time
from underautomation.yaskawa.yaskawa_robot import YaskawaRobot
from underautomation.yaskawa.connect_parameters import ConnectParameters
from underautomation.yaskawa.high_speed_e_server.alarm_reset_type import AlarmResetType
from underautomation.yaskawa.high_speed_e_server.switching_commands import SwitchingCommands
from underautomation.yaskawa.high_speed_e_server.on_off_command_type import OnOffCommandType

##
robot = YaskawaRobot()
robot.connect(ConnectParameters("192.168.0.1"))
hses = robot.high_speed_e_server

# 1. Check the mode: play and remote
status = hses.get_status_information()
if not status.play or not status.command_remote:
    raise RuntimeError("Set the controller in play mode and remote mode")

# 2. Reset a pending alarm
if status.alarming:
    hses.alarm_reset(AlarmResetType.Reset)

# 3. Select the job at its first line, one cycle, servo on, start
hses.select_job("WELD01", 0)
hses.switching_command(SwitchingCommands.Cycle)
hses.servo_command(OnOffCommandType.Servo, True)
hses.start_job()

# 4. Wait for the end of the job
while True:
    time.sleep(0.2)
    job = hses.get_executing_job_information()
    print(f"{job.name} line {job.line}")
    status = hses.get_status_information()
    if not status.running:
        break

print("Stopped on an alarm" if status.alarming else "Job done")

robot.disconnect()
##
```

The program stops with an error if the controller is not in play mode or not in remote mode. Then it runs the job once, prints its line every 200 ms, and says at the end whether the job ended or stopped on an alarm.

## Stop a job

Hold the robot with `ServoCommand(OnOffCommandType.Hold, true)`: the robot stops on its path. Release the hold and call `StartJob()` to continue, or switch the servo off to end. See [Jobs](/yaskawa/documentation/hses-jobs#hold_and_restart).

## Troubleshooting

- **`Command remote not set`:** the remote mode is off. See [Prepare the controller](/yaskawa/documentation/connect#prepare_the_controller).
- **`Incorrect mode`:** the controller is in teach mode. Turn the mode key to play.
- **`SelectJob` is refused:** the name has the `.JBI` extension, the job does not exist, or `JOB SELECT WHEN REMOTE AND PLAY` is not permitted.
- **`Servo OFF`:** call `ServoCommand(OnOffCommandType.Servo, true)` before `StartJob()`.

## What to read next

- [Jobs](/yaskawa/documentation/hses-jobs): the reference of the job methods.
- [Read and reset alarms](/yaskawa/documentation/how-to-read-reset-alarms).