Registers & variables
Read and write numeric, position, and string registers, system variables, and perform batch operations via CGTP.
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 valueCgtpVariableValue var1 = robot.Cgtp.ReadVariable("$RMT_MASTER");int intVal = var1.IntegerValue;CgtpVariableType type = var1.Type;// Read as raw stringstring raw = robot.Cgtp.ReadVariableAsString("$MCR.$GENOVERRIDE");// Write a variablerobot.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");}}
Supported types
The variable type is auto-detected. You can access the appropriate typed property:
| Type | Property |
|---|---|
| Integer | IntegerValue |
| Real | RealValue |
| Boolean | BooleanValue |
| String | StringValue |
| CartesianPosition | CartesianPositionValue |
| JointPosition | JointPositionValue |
| Vector | VectorValue |
| Config | ConfigurationValue |
Read and Write registers
FanucRobot robot = new FanucRobot();robot.Connect("192.168.0.1");// Numeric registersNumericRegisterWithComment 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 registersPositionRegisterWithComment 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 registersStringRegisterWithComment[] allStr = robot.Cgtp.ReadStringRegistersWithComment();robot.Cgtp.WriteStringRegister(1, "Hello from CGTP");}}
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 batchvar 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 onceCgtpBatchReadResult result = robot.Cgtp.ReadBatchVariables(batch);// Write batch with valuesvar writeBatch = new CgtpBatchVariables();writeBatch.AddNumericRegisterAsReal(1, "Speed", 50.0);writeBatch.AddNumericRegisterAsInteger(2, "Counter", 0);writeBatch.AddStringRegisterWithValue(1, "Status", "Running");robot.Cgtp.WriteBatchVariables(writeBatch);}}
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 stringstring raw = robot.Cgtp.ReadVariableAsString("$MCR.$GENOVERRIDE");// Write a variablerobot.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
Represents the value of a controller variable with its data type.
| Member | Type | Description |
|---|---|---|
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 |
Data types that can be returned when reading a controller variable.
| Name | Value | Description |
|---|---|---|
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. |
Collection of batch variables to read from or write to the controller in a single operation. Provides convenience methods to add typed variables.
| Member | Type | Description |
|---|---|---|
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.
|
AddNumericRegisterAsInteger(int, string, int) Method | CgtpNumericRegister | Add a numeric register with an integer value and comment for writing.
|
AddNumericRegisterAsReal(int, string, double) Method | CgtpNumericRegister | Add a numeric register with a real (double) value and comment for writing.
|
AddPositionRegister(int, int) Method | CgtpPositionRegister | Add a position register for reading. The position data will be populated after a batch read.
|
AddPositionRegisterAsCartesian(int, CartesianPosition, int, string) Method | CgtpPositionRegister | Add a position register with a Cartesian position for writing.
|
AddPositionRegisterAsJoint(int, JointsPosition, int, string) Method | CgtpPositionRegister | Add a position register with a joint position for writing.
|
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.
|
AddStringRegisterWithValue(int, string, string) Method | CgtpStringRegister | Add a string register with a value and comment for writing.
|
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.
|
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 |
Represents a numeric register with an associated comment.
| Member | Type | Description |
|---|---|---|
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 |
Represents a position register with an associated comment.
| Member | Type | Description |
|---|---|---|
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. |