API. RAPID

The API.RAPID namespace provides a comprehensive set of interfaces for managing and interacting with RAPID programs on the controller. It includes methods for controlling program execution, managing tasks, modules, and variables, as well as monitoring execution states and subscribing to variable changes. This class simplifies the development and integration of RAPID-based automation solutions, enabling developers to efficiently interact with and control RAPID programs.

Classes

RecordData
Task
Variable
VariableBool
VariableJointTarget
VariableNum
VariableRobTarget
VariableString

Members

(constant) MODULETYPE :string

Type:
  • string
Properties
NameTypeDescription
Programenum

Program module

Systemenum

System module

Programstring
Systemstring

Methods

createVariableInstance(module, name, task)

Creates a variable instance.

Parameters:
NameTypeDescription
modulestring

The name of the module where the variable locates..

namestring

The variable name.

taskstring

The task name.

Example
let variableInstance = await API.RAPID.createVariableInstance("MainModule","aa");

getProgramPointer() → {Promise.<objecy>}

Gets the program pointer

Returns:

A promise with an object containing the program pointer information.

Type: 
Promise.<objecy>
Example
await API.RAPID.getProgramPointer()

getTask(task) → {Promise.<object>}

Gets an instance of a API.RAPID.Task class

Parameters:
NameTypeDescription
taskstring

Task name

Returns:
  • API.RAPID.Task
Type: 
Promise.<object>
Example
await API.RAPID.getTask();

getValRecordTypes(taskopt) → {Promise.<object>}

Gets available value-type RAPID RECORDs.

Parameters:
NameTypeAttributesDescription
taskstring<optional>

The task name.

Returns:
Type: 
Promise.<object>
Example
await API.RAPID.getVariableTypes('T_ROB1')

getVariableProperties(module, name, task)

Gets the properties of a variable

Parameters:
NameTypeDescription
modulestring

The name of the module where the variable locates.

namestring

The variable name

taskstring

The task name

Example
let props = await API.RAPID.getVariableProperties("MainModule","aa");

getVariableType(module, name, task)

Gets the data type of a RAPID variable

Parameters:
NameTypeDescription
modulestring

The name of the module where the variable locates.

namestring

The variable name

taskstring

The task name

Example
let type = await API.RAPID.getVariableType("MainModule","aa");

getVariableValue(module, name, task)

Get the value of a variable

Parameters:
NameTypeDescription
modulestring

The name of the module where the variable locates.

namestring

The variable name

taskstring

The task name

Example
let value = await API.RAPID.getVariableValue("MainModule","aa");

(async) loadModule(path, replace, taskName, requestMshopt)

Load a module from the controller HOME files

Parameters:
NameTypeAttributesDefaultDescription
pathstring

Path to the module file in the HOME directory (included extension of the module).

replacebooleanfalse

f true, it will replace an existing module in RAPID with the same name

taskNamestringT_ROB1

The name of the task to which the module belongs.

requestMshboolean<optional>
true

Edit mastership needs to be requested before loading the module.

Example
let url = `${this.path}/${this.name}${this.extension}`;
await API.RAPID.loadModule(url, true);

monitorExecutionState(callbackopt)

Monitors the state change of the RAPID program execution. It is possible to call a callback function every time the state is changed. Current state is stored in executionState variable. Additionally, isRunning is updated correspondingly.

Parameters:
NameTypeAttributesDescription
callbackfunction<optional>

The callback function that is called when the execution state changes.

Example
// The callback will be executed when execution status is changed
const execStatus = (value)=>{console.log("Execution status is:",value);}
await API.RAPID.monitorExecutionState(execStatus);

searchRoutines(allread, taskName) → {Promise.<Array.<API.RAPID.routines>>}

Searchs all routines

Parameters:
NameTypeDescription
allreadboolean

If the value is set to true, the non-service routines will also be included.

taskNamestring

The task name

Returns:

A list of API.RAPID.routines

Type: 
Promise.<Array.<API.RAPID.routines>>
Example
await task.searchRoutines();

searchTasks(filteropt, caseSensitiveopt) → {Promise.<object>}

Searchs for available tasks.

Parameters:
NameTypeAttributesDescription
filterstring<optional>

Only symbols in the string pattern.

caseSensitiveboolean<optional>

If the value is set to the default "false", non-case-sensitive is applied for the filter; otherwise, case-sensitive is applied.

Returns:
Type: 
Promise.<object>
Example
await API.RAPID.searchTasks()

setCycleMode(cycleMode)

Sets cycle mode

Parameters:
NameTypeDescription
cycleModestring

The value can be 'forever' or 'once'.

Example
await API.RAPID.setCycleMode("once")

setPPToMain()

Sets program pointer to main

Example
await API.RAPID.setPPToMain()

setPPToRoutine()

Sets program pointer to routine

Example
await API.RAPID.setPPToRoutine("MainModule","proc1")

setVariableValue(module, name, value, task, options)

Sets the value of a RAPID variable

Parameters:
NameTypeDescription
modulestring

The name of the module where the variable locates.

namestring

The variable name

valueany

The value to set

taskstring

The task name

optionssetVariableValueOptions

object

Example
await API.RAPID.setVariableValue("MainModule","aa", 2,"T_ROB1",{syncPers:true});

startExecution(cycleMode, execMode, regainMode, setPP, moduleName, procName, taskName)

Starts program execution

Parameters:
NameTypeDescription
cycleModestring

Cycle mode: forever|as_is|once

execModestring

Execution mode: continue|stepin|stepover|stepout|stepback|steplast|stepmotion

regainModestring

Regain mode: continue|regain|clear

setPPboolean

Set program pointer to main if has no pp

moduleNamestring

Module name

procNamestring

Procedure name

taskNamestring

Task name

Example
await API.RAPID.startExecution({moduleName: "Wizard", procName: "test1"});

stopExecution(props)

Stops the RAPID execution with the settings given in the parameter object. All or any of the defined parameters can be supplied, if a value is omitted a default value will be used. The default values are: stopMode = 'stop', and useTSP = 'normal'

Parameters:
NameTypeDescription
propsstopExecutionProps
Example
await API.RAPID.stopExecution();

(async) unloadModule(moduleName, taskNameopt)

Unloads a RAPID module

Parameters:
NameTypeAttributesDefaultDescription
moduleNamestring

The module name.

taskNamestring<optional>
T_ROB1

The task name.

Example
await API.RAPID.unloadModule("Module1")

Type Definitions

RoutineSymbolType

;

Type:
  • 'procedure' | 'function' | 'trap'

VariableProps

Properties
NameTypeAttributesDescription
taskNamestring<optional>

The task name

moduleNamestring<optional>

The module name

symbolNamestring<optional>

The symbol name

dataTypestring<optional>

The symbol's data type

symbolTypestring<optional>

The declaration type of the data, valid values: 'constant' 'variable' 'persistent'

dimensionsArray.<number>

List of dimensions for arrays

scopestring<optional>

The data's scope, valid values: 'local' 'task' 'global'

dataTypeURLstring<optional>

RWS URL to the data’s type symbol

VariableSymbolType

;

Type:
  • 'constant' | 'variable' | 'persistent'

filterRoutines

Properties
NameTypeAttributesDescription
namestring<optional>

Name of the data symbol (not case-sensitive)

symbolTypeRoutineSymbolType<optional>

Valid values: 'procedure', 'function', 'trap' , 'routine'(array with multiple values is supported)

filterVariables

Properties
NameTypeAttributesDescription
namestring<optional>

Name of the data symbol (not case-sensitive)

symbolTypeVariableSymbolType<optional>

Valid values: 'constant', 'variable', 'persistent' (array with multiple values is supported)

dataTypestring<optional>

Type of the data, e.g. 'num'(only one data type is supported) i.e. a type declaration that has no declared variable will not be returned when this flag is set true.

searchSymbolProps

Properties
NameTypeAttributesDescription
taskstring<optional>

The task where the searching runs. (default: 'T_ROB1')

modulestring<optional>

The module where the searching runs.

isInUseboolean<optional>

Only return symbols that are used in a RAPID program, i.e. a type declaration that has no declared variable will not be returned when this flag is set true.

dataTypeobject<optional>

Type of the data, e.g. 'num'(only one data type is supported)

symbolTypenumber<optional>

Can be the following values:
 undefined: 0
 constant: 1
 variable: 2
 persistent: 4
 function: 8
 procedure: 16
 trap: 32
 module: 64
 task: 128
 routine: 8 + 16 + 32
 rapidData: 1 + 2 + 4
 any: 255

namestring | Array<optional>

Name of the data symbol (not case-sensitive)

setVariableValueOptions

Properties
NameTypeAttributesDefaultDescription
syncPersboolean<optional>
false

If the value is set to true, the variable value is synchronized immediately; otherwise, the variable value will be synchronized until next synchronization action; Set to false if RAPID program is running;

stopExecutionProps

Properties
NameTypeAttributesDescription
stopModeRWS.Rapid.StopModes<optional>

Stop mode, valid values: 'cycle', 'instruction', 'stop' or 'quick_stop'

useTSPRWS.Rapid.UseTSPOptions.normal<optional>

Use task selection panel, valid values: 'normal' or 'all_tasks'