This article shows how to read and write the inputs and outputs of a Yaskawa Motoman controller from a PC, in C# or Python. It gives a complete program that sets a network input, waits for a general output, then clears the input.

## Prerequisites

- The SDK is connected to the controller: see [Connect to your robot](/yaskawa/documentation/connect).
- The job or the ladder of the controller uses the network inputs that the PC writes.

## Three calls

| Step                       | Method                                 | Note                                   |
| -------------------------- | -------------------------------------- | -------------------------------------- |
| Read one or more groups    | `ReadIO(IOType, group, count)`         | One byte per group, one bit per signal |
| Write network input groups | `WriteIoNetworkInput(group, bytes)`    | An even number of groups               |
| Number of a signal         | `IoHelpers.ConvertIOGroupToBitAddress` | `#10013` = group 1001, bit 3           |

The PC writes only the network inputs. To act on the cell, the job or the ladder of the controller reads them and switches its outputs.

## Example

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

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

        // 1. Signal #27013: bit 3 of group 1 of the network inputs
        const ushort group = 1;
        const int bit = 3;

        // 2. Set the bit, keep the other bits of the group
        byte current = robot.HighSpeedEServer.ReadIO(IOType.NetworkInput, group, 2).Value[0];
        byte next = (byte)(current | (1 << bit));
        robot.HighSpeedEServer.WriteIoNetworkInput(group, new byte[] { next, 0 });

        // 3. Wait for the general output #10010 (bit 0 of group 1), at most 10 seconds
        DateTime timeout = DateTime.Now.AddSeconds(10);
        while ((robot.HighSpeedEServer.ReadIO(IOType.GeneralOutput, 1, 2).Value[0] & 1) == 0)
        {
            if (DateTime.Now > timeout) throw new TimeoutException("#10010 stayed off");
            Thread.Sleep(50);
        }

        // 4. Clear the network input
        robot.HighSpeedEServer.WriteIoNetworkInput(group, new byte[] { (byte)(next & ~(1 << bit)), 0 });

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

**Python : HowToReadWriteIo**
```python
import time
from underautomation.yaskawa.yaskawa_robot import YaskawaRobot
from underautomation.yaskawa.connect_parameters import ConnectParameters
from underautomation.yaskawa.common.io_type import IOType

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

# 1. Signal #27013: bit 3 of group 1 of the network inputs
group = 1
bit = 3

# 2. Set the bit, keep the other bits of the group
current = robot.high_speed_e_server.read_io(IOType.NetworkInput, group, 2).value[0]
next_value = current | (1 << bit)
robot.high_speed_e_server.write_io_network_input(group, [next_value, 0])

# 3. Wait for the general output #10010 (bit 0 of group 1), at most 10 seconds
timeout = time.monotonic() + 10
while (robot.high_speed_e_server.read_io(IOType.GeneralOutput, 1, 2).value[0] & 1) == 0:
    if time.monotonic() > timeout:
        raise TimeoutError("#10010 stayed off")
    time.sleep(0.05)

# 4. Clear the network input
robot.high_speed_e_server.write_io_network_input(group, [next_value & ~(1 << bit), 0])

robot.disconnect()
##
```

The program:

1. takes the signal `#27013`: bit 3 of the group 1 of the network inputs;
2. reads the group, sets the bit and writes the group back, so that the other bits keep their state;
3. reads the general output `#10010` every 50 ms until it is on, with a timeout of 10 s;
4. clears the bit.

## Signal numbers

A signal number has 5 digits: the group, then the bit. The group of a type starts at a fixed number: `1` for the general inputs, `1001` for the general outputs, `2701` for the network inputs. The table of every type is in [Inputs and outputs](/yaskawa/documentation/hses-io#signals_groups_and_bits).

## Troubleshooting

- **The write is refused:** the PC can write only the network inputs. Use a network input and let the ladder copy it to an output.
- **The write needs an even number of values:** write two groups. Read them first so that the second group keeps its state.
- **The bit does not change on the pendant:** check that you test the right bit. The bit 0 is the signal ending with `0`.

## What to read next

- [Inputs and outputs](/yaskawa/documentation/hses-io): the I/O types and the reference.
- [Monitor the state of the robot](/yaskawa/documentation/how-to-monitor-state).