Read and write variables
Exchange data with a Yaskawa job from C# or Python: integer, real, byte and string variables, which type to choose, and the frequent errors.
This article shows how to exchange data between a PC and a job of a Yaskawa Motoman controller, in C# or Python, with the variables of the controller. It gives a complete program that reads a counter and writes offsets, a recipe number and a reference.
Prerequisites
- The SDK is connected to the controller: see Connect to your robot.
- The job uses the variables that the PC reads and writes. Agree on the numbers of these variables with the author of the job.
Which variable to choose
| Data | Variable | Methods |
|---|---|---|
| A flag, a small number (0 to 255) | B | ReadByte, WriteByte |
| A counter, an index (-32768 to 32767) | I | ReadInteger, WriteInteger |
| A large integer | D | ReadDoubleInteger, WriteDoubleInteger |
| A measure, an offset in mm | R | ReadReal, WriteReal |
| A text, a reference | S | Read16BytesChar, Write16BytesChar |
| A position | P | ReadPositionVariable, WritePositionVariable |
Each method reads or writes several variables in a row, in one request.
Example
using UnderAutomation.Yaskawa;using UnderAutomation.Yaskawa.HighSpeedEServer;public class HowToReadWriteVariables{static void Main(){var robot = new YaskawaRobot();robot.Connect("192.168.0.1");// Integer I000: a part counter written by the jobshort count = robot.HighSpeedEServer.ReadInteger(0, 1).Value[0];Console.WriteLine($"Parts: {count}");// Real R000 and R001: offsets used by the job, in mmrobot.HighSpeedEServer.WriteReal(0, new[] { 2.5f, -1.0f });// Byte B000 and B001: a recipe number and a flag. Bytes go by pairsrobot.HighSpeedEServer.WriteByte(0, new byte[] { 7, 1 });// String S000: the reference of the partrobot.HighSpeedEServer.Write16BytesChar(0, new[] { "REF-2026-118" });// Check what the controller storedbyte[] bytes = robot.HighSpeedEServer.ReadByte(0, 2).Value;float[] reals = robot.HighSpeedEServer.ReadReal(0, 2).Value;Console.WriteLine($"B000={bytes[0]} B001={bytes[1]} R000={reals[0]} R001={reals[1]}");robot.Disconnect();}}
The program:
- reads
I000, a counter of the job; - writes two offsets in
R000andR001; - writes a recipe number and a flag in
B000andB001, as a pair; - writes a reference in
S000; - reads the variables back to check them.
A handshake with the job
A job and a PC read and write the same variables at the same time. Use one variable as a flag: the PC writes the data, then sets the flag. The job waits for the flag, reads the data, then clears the flag. The PC waits for the cleared flag before it writes again.
Troubleshooting
- The write of
Bvariables is refused: write an even number of values. InvalidDataAnswerExceptionon a variable number: the number is out of the range of the controller. The ranges depend on the controller and on its settings.- A text is cut: a 16 byte string keeps 16 characters. Use the 32 byte strings when the controller has them.
What to read next
- Variables and registers: all the variable types, including positions.
- Run a job.