UnderAutomation
Any question?

[email protected]

Contact us
UnderAutomation
⌘Q

Registers & variables

Read and write numeric, position, and string registers, system variables, and perform batch operations via CGTP.

  • Read a variable
  • Supported types
  • Read and Write registers
  • Batch variables
  • Complete example
  • API reference

CGTP lets you read and write any system variable, program variable, and register (numeric, position, string) on your Fanuc robot.

Read a variable

ReadVariable returns a typed CgtpVariableValue with automatic parsing:

FanucRobot robot = new FanucRobot();
robot.Connect("192.168.0.1");
// Read as typed value
CgtpVariableValue var1 = robot.Cgtp.ReadVariable("$RMT_MASTER");
int intVal = var1.IntegerValue;
CgtpVariableType type = var1.Type;
// Read as raw string
string raw = robot.Cgtp.ReadVariableAsString("$MCR.$GENOVERRIDE");
// Write a variable
robot.Cgtp.WriteVariable("$RMT_MASTER", 1);
robot.Cgtp.WriteVariable("$MCR.$GENOVERRIDE", 50.0);
// Program-scoped variables (Karel)
CgtpVariableValue karelVar = robot.Cgtp.ReadVariable("my_variable", progName: "MY_KAREL");
robot.Cgtp.WriteVariable("my_variable", 42, progName: "MY_KAREL");
}
}
Click to see the full code

Supported types

The variable type is auto-detected. You can access the appropriate typed property:

TypeProperty
IntegerIntegerValue
RealRealValue
BooleanBooleanValue
StringStringValue
CartesianPositionCartesianPositionValue
JointPositionJointPositionValue
VectorVectorValue
ConfigConfigurationValue

Read and Write registers

FanucRobot robot = new FanucRobot();
robot.Connect("192.168.0.1");
// Numeric registers
NumericRegisterWithComment reg = robot.Cgtp.ReadNumericRegisterWithComment(1);
Console.WriteLine($"R[1] = {reg.RealValue}, Comment: {reg.Comment}");
NumericRegisterWithComment[] allRegs = robot.Cgtp.ReadNumericRegistersWithComment();
robot.Cgtp.WriteNumericRegisterAsDouble(5, 123.45);
robot.Cgtp.WriteNumericRegisterAsInteger(5, 100);
// Position registers
PositionRegisterWithComment posReg = robot.Cgtp.ReadPositionRegisterWithComment(1);
robot.Cgtp.WritePositionRegisterAsCartesian(1, new CartesianPosition(100, 200, 300, 0, 90, 0));
robot.Cgtp.WritePositionRegisterAsJoint(1, new JointsPosition { J1 = 0, J2 = 0, J3 = 0, J4 = 0, J5 = 0, J6 = 0 });
// String registers
StringRegisterWithComment[] allStr = robot.Cgtp.ReadStringRegistersWithComment();
robot.Cgtp.WriteStringRegister(1, "Hello from CGTP");
}
}
Click to see the full code

Batch variables

Read or write multiple registers and variables in a single HTTP request:

FanucRobot robot = new FanucRobot();
robot.Connect("192.168.0.1");
// Create a batch
var batch = new CgtpBatchVariables();
batch.AddNumericRegister(1);
batch.AddNumericRegister(2);
batch.AddStringRegister(1);
batch.AddPositionRegister(1);
batch.AddVariable("$RMT_MASTER");
batch.AddVariable("$MCR.$GENOVERRIDE");
// Read all at once
CgtpBatchReadResult result = robot.Cgtp.ReadBatchVariables(batch);
// Write batch with values
var writeBatch = new CgtpBatchVariables();
writeBatch.AddNumericRegisterAsReal(1, "Speed", 50.0);
writeBatch.AddNumericRegisterAsInteger(2, "Counter", 0);
writeBatch.AddStringRegisterWithValue(1, "Status", "Running");
robot.Cgtp.WriteBatchVariables(writeBatch);
}
}
Click to see the full code

Complete example

using UnderAutomation.Fanuc;
using UnderAutomation.Fanuc.Common;
using UnderAutomation.Fanuc.Cgtp;
using UnderAutomation.Fanuc.Cgtp.BatchVariables;
public class CgtpRegistersVariables
{
public static void Main()
{
FanucRobot robot = new FanucRobot();
ConnectionParameters parameters = new ConnectionParameters("192.168.0.1");
parameters.Cgtp.Enable = true;
robot.Connect(parameters);
// --- Read variables ---
CgtpVariableValue var = robot.Cgtp.ReadVariable("$RMT_MASTER");
int intVal = var.IntegerValue;
CgtpVariableType type = var.Type;
// Read as raw string
string raw = robot.Cgtp.ReadVariableAsString("$MCR.$GENOVERRIDE");
// Write a variable
robot.Cgtp.WriteVariable("$RMT_MASTER", 1);
robot.Cgtp.WriteVariable("$MCR.$GENOVERRIDE", 50.0);
// --- Program-scoped variables ---
CgtpVariableValue karelVar = robot.Cgtp.ReadVariable("my_variable", progName: "MY_KAREL");
robot.Cgtp.WriteVariable("my_variable", 42, progName: "MY_KAREL");
// --- Numeric registers ---
NumericRegisterWithComment reg = robot.Cgtp.ReadNumericRegisterWithComment(1);
robot.Cgtp.WriteNumericRegisterAsDouble(5, 123.45);
robot.Cgtp.WriteNumericRegisterAsInteger(5, 100);
// --- Position registers ---
PositionRegisterWithComment posReg = robot.Cgtp.ReadPositionRegisterWithComment(1);
robot.Cgtp.WritePositionRegisterAsCartesian(1, new CartesianPosition(100, 200, 300, 0, 90, 0));
robot.Cgtp.WritePositionRegisterAsJoint(1, new JointsPosition { J1 = 0, J2 = 0, J3 = 0, J4 = 0, J5 = 0, J6 = 0 });
// --- String registers ---
StringRegisterWithComment[] allStr = robot.Cgtp.ReadStringRegistersWithComment();
robot.Cgtp.WriteStringRegister(1, "Hello from CGTP");
// --- Batch read ---
var batch = new CgtpBatchVariables();
batch.AddNumericRegister(1);
batch.AddNumericRegister(2);
batch.AddStringRegister(1);
batch.AddPositionRegister(1);
batch.AddVariable("$RMT_MASTER");
CgtpBatchReadResult result = robot.Cgtp.ReadBatchVariables(batch);
// --- Batch write ---
var writeBatch = new CgtpBatchVariables();
writeBatch.AddNumericRegisterAsReal(1, "Speed", 50.0);
writeBatch.AddNumericRegisterAsInteger(2, "Counter", 0);
writeBatch.AddStringRegisterWithValue(1, "Status", "Running");
robot.Cgtp.WriteBatchVariables(writeBatch);
}
}

API reference

Class
CgtpVariableValue
C#Python

Represents the value of a controller variable with its data type.

MemberTypeDescription
BooleanValue
Property
read only
bool
Value interpreted as a boolean (TRUE/FALSE).
CartesianPositionValue
Property
read only
CartesianPositionVariable
Value interpreted as a Cartesian position.
ConfigurationValue
Property
read only
Configuration
Value interpreted as a robot configuration.
IntegerValue
Property
read only
int
Value interpreted as an integer.
JointPositionValue
Property
read only
JointPositionVariable
Value interpreted as a joint position.
RealValue
Property
read only
double
Value interpreted as a double-precision floating-point number.
StringLength
Property
read only
int
Maximum string length if the variable type is String
StringValue
Property
read only
string
Raw string value of the variable
Type
Property
read only
CgtpVariableType
Data type of the variable
VectorValue
Property
read only
VectorVariable
Value interpreted as a 3D vector.
ToString()
Method
string
Enum
CgtpVariableType
C#Python

Data types that can be returned when reading a controller variable.

NameValueDescription
Boolean
18
Boolean value (TRUE or FALSE).
Byte
24
8-bit byte value.
CartesianPosition
2
Cartesian position (X, Y, Z, W, P, R with configuration).
Config
28
Robot configuration string.
Integer
16
32-bit integer value.
JointPose9
8601
Joint position with up to 9 axes.
JointPosition
9
Joint position (J1..J9).
Numeric
38
Numeric value that can be either integer or real.
POSITION
257
Full position type.
Real
17
Double-precision floating-point value.
Short
23
16-bit short integer value.
String
7936
String value. The actual type code encodes the maximum string length.
Vector
19
3D vector (X, Y, Z).
XYZWPR
256
XYZWPR position type.
XYZWPRExt
262
Extended XYZWPR position with additional axes.
Class
CgtpBatchVariables
C#Python

Collection of batch variables to read from or write to the controller in a single operation. Provides convenience methods to add typed variables.

MemberTypeDescription
CgtpBatchVariables()
Constructor
Count
Property
read only
int
IsReadOnly
Property
read only
bool
this[int]
Property
ICgtpBatchVariable
Add(ICgtpBatchVariable)
Method
void
AddNumericRegister(int)
Method
CgtpNumericRegister
Add a numeric register for reading. The value and comment will be populated after a batch read.
  • index : 1-based register index (R[index])
AddNumericRegisterAsInteger(int, string, int)
Method
CgtpNumericRegister
Add a numeric register with an integer value and comment for writing.
  • index : 1-based register index (R[index])
  • comment : Register comment (mandatory)
  • value : Integer value to write
AddNumericRegisterAsReal(int, string, double)
Method
CgtpNumericRegister
Add a numeric register with a real (double) value and comment for writing.
  • index : 1-based register index (R[index])
  • comment : Register comment (mandatory)
  • value : Real value to write
AddPositionRegister(int, int)
Method
CgtpPositionRegister
Add a position register for reading. The position data will be populated after a batch read.
  • index : 1-based register index (PR[index])
  • group : Motion group number (default 1)
AddPositionRegisterAsCartesian(int, CartesianPosition, int, string)
Method
CgtpPositionRegister
Add a position register with a Cartesian position for writing.
  • index : 1-based register index (PR[index])
  • position : Cartesian position to write
  • group : Motion group number (default 1)
  • comment : Optional comment. Null means no comment is written.
AddPositionRegisterAsJoint(int, JointsPosition, int, string)
Method
CgtpPositionRegister
Add a position register with a joint position for writing.
  • index : 1-based register index (PR[index])
  • position : Joint position to write
  • group : Motion group number (default 1)
  • comment : Optional comment. Null means no comment is written.
AddRange(IEnumerable<ICgtpBatchVariable>)
Method
void
Add multiple variables at once.
AddStringRegister(int)
Method
CgtpStringRegister
Add a string register for reading. The value and comment will be populated after a batch read.
  • index : 1-based register index (SR[index])
AddStringRegisterWithValue(int, string, string)
Method
CgtpStringRegister
Add a string register with a value and comment for writing.
  • index : 1-based register index (SR[index])
  • comment : Register comment (mandatory)
  • value : String value to write
AddVariable(string, string)
Method
CgtpVariable
Add a generic variable for reading or writing. For system variables, leave programName null. Set the desired value on the returned object before performing a batch write.
  • name : Full variable name (e.g. "$RMT_MASTER", "$MNUTOOL[1,1]")
  • programName : Program name that owns the variable. Null for system variables.
Clear()
Method
void
Contains(ICgtpBatchVariable)
Method
bool
CopyTo(ICgtpBatchVariable[], int)
Method
void
GetEnumerator()
Method
IEnumerator<ICgtpBatchVariable>
IndexOf(ICgtpBatchVariable)
Method
int
Insert(int, ICgtpBatchVariable)
Method
void
Remove(ICgtpBatchVariable)
Method
bool
RemoveAt(int)
Method
void
Class
NumericRegisterWithCommentinherits NumericRegister
C#Python

Represents a numeric register with an associated comment.

MemberTypeDescription
NumericRegisterWithComment()
Constructor
Default constructor.
NumericRegisterWithComment(double, string)
Constructor
Creates a numeric register with a real value and comment.
NumericRegisterWithComment(int, string)
Constructor
Creates a numeric register with an integer value and comment.
NumericRegisterWithComment(string)
Constructor
Creates a numeric register with a comment.
Comment
Property
string
Comment associated with this register.
ToString()
Method
string
Class
PositionRegisterWithCommentinherits PositionRegister
C#Python

Represents a position register with an associated comment.

MemberTypeDescription
PositionRegisterWithComment()
Constructor
Default constructor.
Comment
Property
string
Comment associated with this position register.
Parse(string)
Method
static
PositionRegisterWithComment
Parses a position register with comment from its string representation.

Easily integrate Universal Robots, Fanuc, Yaskawa, ABB or Staubli robots into your .NET, Python, LabVIEW or Matlab applications

UnderAutomation
Contact usLegal

© All rights reserved.