KCL commands
Send KCL commands through the web server instead of Telnet. Unsafe commands without result, and when to use RunProgram.
robot.Cgtp.Kcl sends KCL commands (Karel Command Language) through the web server of the controller. It has the same methods and the same result types as the Telnet KCL client robot.Telnet, without the Telnet protocol.
Use it instead of Telnet KCL for new developments. Telnet KCL is a legacy protocol: it is not secured, and its behavior changes with the firmware version and on ROBOGUIDE.
Why CGTP instead of Telnet
Telnet KCL (robot.Telnet) | KCL over CGTP (robot.Cgtp.Kcl) | |
|---|---|---|
| Setup on the robot | Telnet password, J541 security level, special port on ROBOGUIDE | None, CGTP is enabled by default in the SDK |
| Security | Password and commands sent in clear text | Web server of the controller, optional HTTP authentication |
| Firmware | Answers change with the version and on ROBOGUIDE | V8.30 and later, V9.30 and later for the Unsafe commands |
| Result of the commands | Text answer of the controller for every command | No result for the Unsafe commands (see below) |
Move from Telnet to CGTP
Replace robot.Telnet by robot.Cgtp.Kcl. The method names, the parameters and the result types do not change. You can remove the Telnet parameters of the connection.
static void Main(){FanucRobot robot = new FanucRobot();// CGTP is enabled by default: no Telnet password and no Telnet setup on the robotrobot.Connect("192.168.0.1");// Before: robot.Telnet.SetVariable("$RMT_MASTER", 1);SetVariableResult result = robot.Cgtp.Kcl.SetVariable("$RMT_MASTER", 1);if (!result.Succeed){Console.WriteLine(result.ErrorText);}// Before: robot.Telnet.GetTaskInformation("MY_PROGRAM");TaskInformationResult task = robot.Cgtp.Kcl.GetTaskInformation("MY_PROGRAM");Console.WriteLine($"{task.TaskStatus} at line {task.CurrentLine}");}}
Unsafe commands
Some KCL commands are sent in Unsafe mode through CGTP. The controller executes them but returns no status and no error. The result object always reports a success (Succeed is true, ErrorText is empty), even if the controller refused the command, for example because the program does not exist or because the device has no motion control.
These commands need firmware V9.30 or later:
| Method | Action |
|---|---|
Run | Start a program |
Pause | Pause a program |
Hold | Hold a program |
Continue | Resume a paused or held program |
Abort, AbortAll | Abort one or all tasks |
ClearProgram, ClearVars | Clear a program or its variables from memory |
StepOn, StepOff | Enable or disable the step mode |
SendCustomCommandUnsafe | Send any KCL command without reading the answer |
The other commands (GetVariable, SetVariable, SetPort, Simulate, Reset, GetTaskInformation, breakpoints, SendCustomCommand...) return the answer of the controller, like with Telnet. The controller refuses some commands when they come from the web server: Succeed is then false and ErrorText gives the message of the controller.
After an Unsafe command, check the state of the controller yourself if your application depends on it: read the task status with GetTaskInformation(), or read a variable or an I/O.
FanucRobot robot = new FanucRobot();robot.Connect("192.168.0.1");// Unsafe command: the result is always a success, even if the controller refused the commandrobot.Cgtp.Kcl.Pause("MY_PROGRAM");// Check the effect with a command that returns a resultTaskInformationResult task = robot.Cgtp.Kcl.GetTaskInformation("MY_PROGRAM");if (task.TaskStatus != TaskStatus.Paused){Console.WriteLine("The program is not paused: " + task.TaskStatusStr);}// To start a program, use RunProgram instead of Kcl.Run:// it can start at a given line and throws a CgtpException if the controller refuses the commandrobot.Cgtp.RunProgram("MY_PROGRAM", lineNum: 10);}}
Start a program: prefer RunProgram
To start a program, prefer robot.Cgtp.RunProgram(name, lineNum) to robot.Cgtp.Kcl.Run(name), when the firmware of the controller is V9.30 or later:
- It can start the program at a given line.
Kcl.Runalways starts at the first executable line. - It throws a
CgtpExceptionwhen the controller refuses the command.Kcl.Runreports a success in all cases.
See Program management for the other program functions of CGTP (select, abort, pause).
API reference
KCL client that uses the web server of the controller (CGTP) instead of Telnet. It has the same commands as the Telnet KCL client and does not need a Telnet password. Some commands (Abort, AbortAll, ClearProgram, ClearVars, Continue, Hold, Pause, Run, StepOn, StepOff, SendCustomCommandUnsafe) are sent in Unsafe mode, from firmware V9.30: the controller returns no status, the result always reports a success, and you cannot know if the command was executed. Check the state of the controller after the command, for example with GetTaskInformation() or by reading a variable. To start a program, prefer robot.Cgtp.RunProgram() (firmware V9.30 and later): it can start at a given line and throws a CgtpException when the controller refuses the command.
| Member | Type | Description |
|---|---|---|
Enabled Property read only | bool | Indicates whether the KCL client is currently connected. |
SendCustomCommandUnsafe(string) Method | CustomCommandResult | Sends a custom KCL command in Unsafe mode. Success or failure cannot be determined from the result.
|
SendKclUnsafe<T>(string) Method | <T> | Sends a KCL command in Unsafe mode through the CGTP client. In this mode, the command is always reported as successful because the controller does not return any status or error information. |
SendKcl<T>(string) Method | <T> | Sends a KCL command through the web server of the controller and returns its result. |
Abstract base class for KCL (Keyboard Command Line) clients. Provides all KCL commands shared between Telnet and CGTP implementations.
| Member | Type | Description |
|---|---|---|
KclClientBase() Constructor | ||
Abort(string, bool) Method | ProgramCommandResult | Aborts the specified running or paused task. If program is not specified, the default program Is used. Execution of the current program statement Is completed before the task aborts except for the current motion, DELAY, WAIT, Or READ statements, which are canceled. When used through the CGTP KCL client (Unsafe mode, from firmware 9.30), success or failure cannot be determined from the result.
|
AbortAll(bool) Method | ProgramCommandResult | Aborts all running or paused tasks. Execution of the current program statement Is completed before the task aborts except for the current motion, DELAY, WAIT, Or READ statements, which are canceled. When used through the CGTP KCL client (Unsafe mode, from firmware 9.30), success or failure cannot be determined from the result.
|
AddBreakpoint(string, int) Method | AddBreakpointResult | Add a breakpoint to a specified task
|
ClearAll() Method | ProgramCommandResult | Clears all KAREL and teach pendant programs and variable data from memory. All cleared programs And variables (if they were saved with the SaveVars() command) can be reloaded into memory Using the Load() command. |
ClearProgram(string) Method | ProgramCommandResult | Clears the program data from memory for the specified or default program. When used through the CGTP KCL client (Unsafe mode, from firmware 9.30), success or failure cannot be determined from the result.
|
ClearVars(string) Method | ProgramCommandResult | Clears the variable and type data associated with the specified or default program from memory. Variables And types that are referenced by a loaded program are Not cleared. When used through the CGTP KCL client (Unsafe mode, from firmware 9.30), success or failure cannot be determined from the result.
|
Continue(string) Method | ProgramCommandResult | Continues program execution of the specified task (or all paused tasks if program argument is null) that has been paused by a hold, pause, or test run operation. If the program Is aborted, the program execution Is started at the first executable line. When a task Is paused, the CYCLE START button on the operator panel has the same effect as the Continue() command. Continue is a motion command; therefore, the device from which it Is issued must have motion control. When used through the CGTP KCL client (Unsafe mode, from firmware 9.30), success or failure cannot be determined from the result.
|
GetBreakpoints(string) Method | BreakpointsResult | Returns the breakpoints set on the specified task.
|
GetCurrentPose() Method | GetCurrentPoseResult | Returns the position of the TCP relative to the current user frame of reference with an x, y, and z location in millimeters; w, p, and r orientation in degrees; and the current configuration string. Be sure the robot is calibrated. |
GetTaskInformation(string) Method | TaskInformationResult | Return the task control data for the specified task. If prog_name is not specified, the default program is used
|
GetVariable(string, string) Method | GetVariableResult | Get the name, type, and value of the specified variable. You can display the values of system variables that allow KCL read access or the values of program variables. Use brackets ([]) after the variable name to specify a specific ARRAY element. If you do not specify a specific element the entire variable is displayed.
|
Hold(string) Method | ProgramCommandResult | Pauses the specified or default program that is being executed and holds motion at the current position (after a normal deceleration). Use the Continue() command Or the CYCLE START button On the Operator panel To resume program execution. When used through the CGTP KCL client (Unsafe mode, from firmware 9.30), success or failure cannot be determined from the result.
|
Pause(string, bool) Method | ProgramCommandResult | Pauses the specified running task. If program is not specified, the default program is used. Execution of the current motion segment and the current program statement is completed before the task is paused. Condition handlers remain active. If the condition handler action is NOPAUSE and the condition is satisfied, task execution resumes. If the statement is a WAIT FOR and the wait condition is satisfied while the task is paused, the statement following the WAIT FOR is executed immediately when the task is resumed. If the statement is a DELAY, timing will continue while the task is paused. If the delay time is finished while the task is paused, the statement following the DELAY is immediately executed when the task is resumed. If the statement is a READ, it will accept input even though the task is paused. The Continue() command resumes execution of a paused task. When a task is paused, the CYCLE START button on the operator panel has the same effect as the KCL> CONTINUE command. When used through the CGTP KCL client (Unsafe mode, from firmware 9.30), success or failure cannot be determined from the result.
|
RemoveAllBreakpoints(string) Method | RemoveBreakpointResult | Clear all breakpoints of a specified task
|
RemoveBreakpoint(string, int) Method | RemoveBreakpointResult | Clear a breakpoint of a task at a specified line
|
Reset() Method | ProgramCommandResult | Enables servo power after an error condition has shut off servo power, provided the cause of the error has been cleared. The command also clears the message line on the CRT/KB display. The error message remains displayed if the error condition still exists. The Reset() command has no effect on a program that is being executed. It has the same effect as the FAULT RESET button on the operator panel and the RESET function key on the teach pendant RESET screen. |
Run(string) Method | RunResult | Executes the specified program. The program must be loaded in memory If no program is specified the default program is run. If uninitialized variables are encountered, program execution is paused. Execution begins at the first executable line. RUN is a motion command; therefore, the device from which it is issued must have motion control. If a RUN command is issued in a command file, it is executed as a NOWAIT command. Therefore, the statement following the RUN command will be executed immediately after the RUN command is issued without waiting for the program, specified by the RUN command, to end. When used through the CGTP KCL client (Unsafe mode, from firmware 9.30), success or failure cannot be determined from the result. With CGTP, prefer robot.Cgtp.RunProgram(), which can start at a given line and throws an exception when the controller refuses the command.
|
SendCustomCommand(string) Method | CustomCommandResult | Sends a custom KCL command to the robot and returns the raw result.
|
SendCustomCommand<T>(string) Method | <T> | Sends a custom KCL command to the robot and returns the result as the specified type.
|
SendKclUnsafe<T>(string) Method | <T> | Sends a KCL command in Unsafe mode. When used through the CGTP KCL client, success or failure cannot be determined from the result. |
SendKcl<T>(string) Method | <T> | Sends a KCL command and returns the parsed result. |
SetPort(KCLPorts, int, int) Method | SetPortResult | Assigns the specified value to a specified input or output port. SET PORT can be used either physical Or simulated output ports, but only With simulated input ports.
|
SetVariable(string, double, string) Method | SetVariableResult | Assigns the specified value to the specified variable. You can assign constant values or variable values, but the value must be of the data type that has been declared for the variable. You can assign values to system variables with KCL write access, to program variables, or to standard and user-defined variables and fields. You can assign only one ARRAY element. Use brackets ([]) after the variable name to specify an element. Certain data types like positions and vectors might have more than one value specified.
|
SetVariable(string, int, string) Method | SetVariableResult | Assigns the specified value to the specified variable. You can assign constant values or variable values, but the value must be of the data type that has been declared for the variable. You can assign values to system variables with KCL write access, to program variables, or to standard and user-defined variables and fields. You can assign only one ARRAY element. Use brackets ([]) after the variable name to specify an element. Certain data types like positions and vectors might have more than one value specified.
|
SetVariable(string, string, string) Method | SetVariableResult | Assigns the specified value to the specified variable. You can assign constant values or variable values, but the value must be of the data type that has been declared for the variable. You can assign values to system variables with KCL write access, to program variables, or to standard and user-defined variables and fields. You can assign only one ARRAY element. Use brackets ([]) after the variable name to specify an element. Certain data types like positions and vectors might have more than one value specified.
|
Simulate(KCLPorts, int, int) Method | SimulateResult | Simulating I/O allows you to test a program that uses I/O. Simulating I/O does not actually send output signals or receive input signals. When simulating a port value, you can specify its initial simulated value or allow the initial value to be the same as the physical port value. If no value is specified, the current physical port value is used.
|
StepOff() Method | StepOffResult | Disables step mode. When used through the CGTP KCL client (Unsafe mode, from firmware 9.30), success or failure cannot be determined from the result. |
StepOn(string) Method | StepOnResult | Enables step mode for the specified task. When used through the CGTP KCL client (Unsafe mode, from firmware 9.30), success or failure cannot be determined from the result.
|
Unsimulate(KCLPorts, int) Method | UnsimulateResult | Discontinues simulation of the specified input or output port. When a port is unsimulated, the physical value replaces the simulated value.
|
UnsimulateAll() Method | UnsimulateAllResult | Discontinues simulation on all input or output port. When a port is unsimulated, the physical value replaces the simulated value. |