System variables
Read and write integer, real, position, and string system variables on the Fanuc controller via SNPX.
SNPX lets you read and write system variables by name, including integer, real (float), position, and string types. You can also access Karel program variables using the $[ProgramName]VariableName syntax.
parameters.Snpx.Enable = true;robot.Connect(parameters);// Integer variablesint rmtMaster = robot.Snpx.IntegerSystemVariables.Read("$RMT_MASTER");robot.Snpx.IntegerSystemVariables.Write("$RMT_MASTER", 1);// Real (float) variablesfloat overr = robot.Snpx.RealSystemVariables.Read("$MCR.$GENOVERRIDE");robot.Snpx.RealSystemVariables.Write("$MCR.$GENOVERRIDE", 50.0f);// Position variablesPosition cellFloor = robot.Snpx.PositionSystemVariables.Read("$CELL_FLOOR");robot.Snpx.PositionSystemVariables.Write("$CELL_FLOOR", cellFloor);// String variablesstring lastAlm = robot.Snpx.StringSystemVariables.Read("$ALM_IF.$LAST_ALM");// Karel program variablesint karelVar = robot.Snpx.IntegerSystemVariables.Read("$[MyKarelProg]my_variable");robot.Snpx.IntegerSystemVariables.Write("$[MyKarelProg]my_variable", 42);// Set variable by name (auto-typed)robot.Snpx.SetVariable("$RMT_MASTER", 1);}}
Click to see the full code
Complete example
using UnderAutomation.Fanuc;using UnderAutomation.Fanuc.Common;public class SnpxVariables{public static void Main(){FanucRobot robot = new FanucRobot();ConnectionParameters parameters = new ConnectionParameters("192.168.0.1");parameters.Snpx.Enable = true;robot.Connect(parameters);// --- Integer system variables ---int rmtMaster = robot.Snpx.IntegerSystemVariables.Read("$RMT_MASTER");robot.Snpx.IntegerSystemVariables.Write("$RMT_MASTER", 1);// --- Real (float) system variables ---float genOverride = robot.Snpx.RealSystemVariables.Read("$MCR.$GENOVERRIDE");robot.Snpx.RealSystemVariables.Write("$MCR.$GENOVERRIDE", 50.0f);// --- Position system variables ---Position cellFloor = robot.Snpx.PositionSystemVariables.Read("$CELL_FLOOR");robot.Snpx.PositionSystemVariables.Write("$CELL_FLOOR", cellFloor);// --- String system variables ---string lastAlm = robot.Snpx.StringSystemVariables.Read("$ALM_IF.$LAST_ALM");robot.Snpx.StringSystemVariables.Write("$ALM_IF.$LAST_ALM", "No alarms");// --- Karel program variables ---int karelVar = robot.Snpx.IntegerSystemVariables.Read("$[MyKarelProg]my_variable");robot.Snpx.IntegerSystemVariables.Write("$[MyKarelProg]my_variable", 42);// --- Set variable (auto-detects type) ---robot.Snpx.SetVariable("$RMT_MASTER", 1);}}
API reference
Class
PositionSystemVariablesinherits SnpxWritableAssignableElements<Position,string,PositionSystemVariablesBatchAssignment>Provides access to position system variables on the robot via SNPX.
| Member | Type | Description |
|---|---|---|
GetAssignmentName(string) Method | string | |
GetAssignmentSize(string) Method | int | |
GetAssignmentTarget(string) Method | string | |
Read(string) Method | Position | Reads the position at the specified system variable.
|
ReadFromClient(int, string) Method | Position | Reads a value from the client at the specified memory offset. |
Write(string, CartesianPosition) Method | void | Writes a Cartesian position to the specified system variable.
|
Write(string, ExtendedCartesianPosition) Method | void | Writes an extended Cartesian position to the specified system variable.
|
Write(string, JointsPosition) Method | void | Writes a joints position to the specified system variable.
|
WriteInClient(int, string, Position) Method | void | Writes a value to the robot at the specified offset. |
Class
StringSystemVariablesinherits SnpxWritableAssignableElements<string,string,StringSystemVariablesBatchAssignment>Provides access to string system variables on the robot via SNPX.
| Member | Type | Description |
|---|---|---|
GetAssignmentName(string) Method | string | |
GetAssignmentSize(string) Method | int | |
GetAssignmentTarget(string) Method | string | |
ReadFromClient(int, string) Method | string | Reads a value from the client at the specified memory offset. |
WriteInClient(int, string, string) Method | void | Writes a value to the robot at the specified offset. |