Common Methods
Common methods are ready-made methods that UP provides for code snippets. A snippet calls them like a
function; when UP generates the project, it writes the platform code of each call for the target
platform. Exceptions: this.setInterlock_test and this.resetInterlock_test have no platform code and are
only for set actions in UPact tests; the deprecated getSpecCounter_deprecated of a message cluster does
not have code for every platform.
Two ways to call them
- With a fixed name in front. The name says what the method works on:
this.(the controller of the snippet),math.andstring.(base library),msg.(messages by handle),log.(logger),ref.(reference variables) andproject.(the project). Examples:this.getTimeInStateMs()returns the time in the current state in milliseconds;math.sqrt(x)returns the square root ofx. - On a model element. The method follows the name of an element of a matching type: a child, a
controller interface, a child iterator, a message, a message cluster, a value or variable, or a super
state. Examples:
cylinder.setCommand(command)sets a command on the childcylinder;x.toDINT()casts the valuexto DINT;superState.resetHistory()resets the saved history state of a super state to its initialization state.
In a snippet, a method has the name under which its page lists it.
Where to find them
| Group | How it is called | Page |
|---|---|---|
| Base Lib | math., string. |
Base Lib |
| Child | on a child or a controller interface | Child |
| Child iterator | on a child iterator | Child iterator |
| Controller | this. |
Controller |
| Logger | log. |
Logger |
| Message | msg., on a message or a message cluster |
Message |
| Project | project. |
Project |
| State Machine | on a super state | State Machine |
| Type Cast | on a value or variable | Type Cast |
| Variable Reference | ref. |
Variable Reference |
Methods whose name ends in _dep, _deprecated or _depricated are marked as deprecated by their name.
In UPact tests
Some common methods are marked for use in UPact:
- SetActionCommonControllerContext calls a
this.method marked for set actions on a controller of the test case, for examplesetModeorsetCommand. - SetActionCommonModelContext calls a method of a
message cluster marked for set actions, for example
ack. - TestAction compares the return value of a method marked for test
actions, for example
this.getStateorthis.getMode.
Related
- Custom Namespace: add your own classes and methods through the metamodel.
- ChildIterator, Message handling, Logger
- CodeSnippet Editor