Read and write I/O
Switch a network input and wait for an output of a Yaskawa controller from C# or Python, with the signal numbers, groups and bits explained.
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.
- 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
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 inputsconst ushort group = 1;const int bit = 3;// 2. Set the bit, keep the other bits of the groupbyte 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 secondsDateTime 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 inputrobot.HighSpeedEServer.WriteIoNetworkInput(group, new byte[] { (byte)(next & ~(1 << bit)), 0 });robot.Disconnect();}}
The program:
- takes the signal
#27013: bit 3 of the group 1 of the network inputs; - reads the group, sets the bit and writes the group back, so that the other bits keep their state;
- reads the general output
#10010every 50 ms until it is on, with a timeout of 10 s; - 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.
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: the I/O types and the reference.
- Monitor the state of the robot.