Click or drag to resize

RAPID symbol search

Overview

Most RAPID elements (variables, modules, tasks, records, and so on.) are members of a symbol table, in which their names are stored as part of a program tree structure.

It is possible to search this table and get a collection of RapidSymbol objects, each one including the RAPID object name, location, and type.

SearchRapidSymbol method

The search must be configured carefully, due to the large amount of RAPID symbols in a system. To define a query you need to consider from where in the program tree the search should be performed, which symbols are of interest, and what information you need for the symbols of interest. To enable search from different levels, the SearchRapidSymbol method is a member of several different SDK classes, for example Task, Module and Routine. The following example shows a search performed with Task as the starting point:

C#
RapidSymbol[] rsCol;
rsCol = aTask.SearchRapidSymbol(sProp, "num", string.Empty);
VB
Dim RSCol As RapidSymbol()
RSCol = ATask.SearchRapidSymbol(SProp, "num", string.Empty)

The SearchRapidSymbol method has three arguments. The first argument, of data type RapidSymbolSearchProperties , is detailed in the next section. The second and third arguments are detailed in the following sections.

Search properties

The RapidSymbolSearchProperties type is complex and requires some knowledge about RAPID concepts.

It is used to specify search method, type of RAPID symbol to search for, whether the search should be recursive, whether the symbols are local and/or global, and whether or not the search result should include only symbols currently used by a program. If a property is not valid for a particular symbol, it will be discarded and will not exclude the symbol from the search result.

The table describes the different properties of RapidSymbolSearchProperties.

Property

Description

SearchMethod

Specifies the direction of the search, which can be Block (down) or Scope (up). Example: If the starting point of the search is a routine, a block-search will return the symbols declared within the routine, whereas a scope-search will return the symbols accessible from the routine.

SymbolType

Specifies which RAPID type(s) you want to search for. The SymbolTypes enumeration includes Constant, Variable, Persistent, Function, Procedure, Trap, Module, Task, Routine, RapidData and so on. (Routine includes Function, Procedure and Trap. RapidData includes Constant, Variable and Persistent.)

Recursive

For both block and scope search it is possible to choose if the search should stop at the next scope or block level or recursively continue until the root (or leaf) of the symbol table tree is reached.

GlobalRapidSymbol

Specifies whether global symbols should be included.

LocalRapidSymbol

Specifies whether local symbols should be included.

IsInUse

Specifies whether only symbols in use by the loaded RAPID program should be searched.

Default instance

RapidSymbolSearchProperties has a static method, which returns a default instance.

C#
RapidSymbolSearchProperties sProp = RapidSymbolSearchProperties.CreateDefault();
VB
Dim SProp As RapidSymbolSearchProperties = RapidSymbolSearchProperties.CreateDefault()

The default instance has the following values:

Property

Description

SearchMethod

SymbolSearchMethod.Block

SymbolType

SymbolTypes.NoSymbol

Recursive

True

GlobalRapidSymbol

True

LocalRapidSymbol

True

IsInUse

True

Using this instance you can specify the search properties of the search you want to perform.

Example:

C#
sProp.SearchMethod = SymbolSearchMethod.Scope;
sProp.SymbolType = SymbolTypes.Constant | SymbolTypes.Persistent
sProp.Recursive = false;
VB
SProp.SearchMethod = SymbolSearchMethod.Scope
SProp.SymbolType = SymbolTypes.Constant Or SymbolTypes.Persistent
SProp.Recursive = False
Note Note

The default instance has the property SymbolType set to NoSymbol, which means you need to specify it in order to perform a meaningful search.

Note Note

The SymbolType property allows you to combine several types in the search. For more information, see the preceding example.

Data type argument

The second argument of the SearchRapidSymbol method is the RAPID data type written as a string. The data type should be written with small letters, for example “num”, “string” or “robtarget”. It can also be specified as string.Empty.

Note Note
To search for a UserDefined data type the complete path to the module that holds the RECORD definition must be passed.

For example: result = tRob1.SearchRapidSymbol(sProp,"RAPID/T_ROB1/MyModule/MyDataType", string.Empty);

However, if MyModule is configured as -Shared the system sees its data types as installed, and the task or module should not be included in the path.

result = tRob1.SearchRapidSymbol(sProp,"MyDataType", string.Empty);
Symbol name argument

The third argument is the name of the RAPID symbol. It can be specified as string.Empty if the name of the symbol to retrieve is not known, or if the purpose is to search ALL “num” instances in the system.

Instead of the name of the RAPID symbol a regular expression can be used. The search mechanism will then match the pattern of the regular expression with the symbols in the symbol table. The regular expression string is not case sensitive.

A regular expression is a powerful mechanism. It may consist of ordinary characters and meta characters. A meta character is an operator used to represent one or several ordinary characters, and the purpose is to extend the search.

Within a regular expression, all alphanumeric characters match themselves, that is, the pattern “abc” will only match a symbol named “abc”. To match all symbol names containing the character sequence “abc”, it is necessary to add some meta characters. The regular expression for this is “.*abc.*”.

The available meta character set is shown in the following table:

Expression

Meaning

.

Any single character

^

Any symbol starting with

[s]

Any single character in the non-empty set s, where s is a sequence of characters. Ranges may be specified as c-c.

[^s]

Any single character not in the set s.

r*

Zero or more occurrences of the regular expression r.

r+

One or more occurrences of the regular expression r.

r?

Zero or one occurrence of the regular expression r.

(r)

The regular expression r. Used for separate that regular expression from another.

r | r’

The regular expressions r or r’.

.*

Any character sequence (zero, one or several characters).

Example 1

"^c.*"

Returns all symbols starting with c or C.

Example 2

"^reg[1-3]"

Returns reg1, Reg1, REG1, reg2, Reg2, REG2, reg3, Reg3 and REG3.

Example 3

"^c.*|^reg[1,2]"

Returns all symbols starting with c or C as well as reg1, Reg1, REG1, reg2, Reg2 and REG2.

SearchRapidSymbol example

The following example searches for VAR, PERS or CONST num data in a task and its modules. The search is limited to globally declared symbols. By default the search method is Block, so it does not have to be set.

C#
RapidSymbolSearchProperties sProp = RapidSymbolSearchProperties.CreateDefault();
sProp.SymbolType = SymbolTypes.RapidData;
sProp.LocalRapidSymbol = false;
RapidSymbol[] rsCol;
rsCol = aTask.SearchRapidSymbol(sProp, "num", string.Empty);
VB
Dim sProp As RapidSymbolSearchProperties = RapidSymbolSearchProperties.CreateDefault()
sProp.SymbolTypes = SymbolTypes.RapidData
sProp.LocalRapidSymbol = False
Dim rsCol As RapidSymbol()
rsCol = aTask.SearchRapidSymbol(sProp, "num", string.Empty)
Search for UserDefined RAPID data - example

In the following example an user defined RECORD data type (“mydata”) is declared in a module (“myModule”). Assuming that the end-user can declare and use data of this data type in any program module, the search method must be Block (default). A search for all “mydata” instances may look like this:

C#
 RapidSymbolSearchProperties sProp = RapidSymbolSearchProperties.CreateDefault();
 sProp.SymbolType = SymbolTypes.RapidData;
 RapidSymbol[] rsCol;
rsCol = aTask.SearchRapidSymbol(sProp, "RAPID/T_ROB1/myModule/mydata", string.Empty);
VB
Dim sProp As RapidSymbolSearchProperties = RapidSymbolSearchProperties.CreateDefault()
sProp.SymbolType = SymbolTypes.RapidData
Dim rsCol As RapidSymbol()
rsCol = aTask.SearchRapidSymbol(sProp, "RAPID/T_ROB1/myModule/mydata", string.Empty)
Note Note

If myModule is configured as -Shared and all myData instances are declared in myModule, the search method must be set to Scope and the SearchRapidSymbol call should look like this:

rsCol = aTask.SearchRapidSymbol(sProp, "mydata", string.Empty);