UnderAutomation
Une question ?

[email protected]

Contactez-nous
UnderAutomation
⌘Q
Cette page est disponible uniquement en anglais.

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.

  • Prerequisites
  • Which variable to choose
  • Example
  • A handshake with the job
  • Troubleshooting
  • What to read next

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

DataVariableMethods
A flag, a small number (0 to 255)BReadByte, WriteByte
A counter, an index (-32768 to 32767)IReadInteger, WriteInteger
A large integerDReadDoubleInteger, WriteDoubleInteger
A measure, an offset in mmRReadReal, WriteReal
A text, a referenceSRead16BytesChar, Write16BytesChar
A positionPReadPositionVariable, 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 job
short count = robot.HighSpeedEServer.ReadInteger(0, 1).Value[0];
Console.WriteLine($"Parts: {count}");
// Real R000 and R001: offsets used by the job, in mm
robot.HighSpeedEServer.WriteReal(0, new[] { 2.5f, -1.0f });
// Byte B000 and B001: a recipe number and a flag. Bytes go by pairs
robot.HighSpeedEServer.WriteByte(0, new byte[] { 7, 1 });
// String S000: the reference of the part
robot.HighSpeedEServer.Write16BytesChar(0, new[] { "REF-2026-118" });
// Check what the controller stored
byte[] 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:

  1. reads I000, a counter of the job;
  2. writes two offsets in R000 and R001;
  3. writes a recipe number and a flag in B000 and B001, as a pair;
  4. writes a reference in S000;
  5. 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 B variables is refused: write an even number of values.
  • InvalidDataAnswerException on 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.

Intégrez facilement les robots Universal Robots, Fanuc, Yaskawa, ABB ou Staubli dans vos applications .NET, Python, LabVIEW ou Matlab

UnderAutomation
Contactez-nousLegal

© All rights reserved.