3.3 Uses of Expressions
3.3.1 Parameters
The values of most parameters of actors can be given as expressions1. The variables in the expression refer to other parameters that are in scope, which are those contained by the same container or some container above in the hierarchy. They can also reference variables in a scope-extending attribute, which includes variables defining units, as explained below in section 3.10. Adding parameters to actors is straightforward, as explained in the previous chapter.
3.3.2 Port Parameters
It is possible to define a parameter that is also a port. Such a PortParameter provides a default value, which is specified like the value of any other parameter. When the corresponding port receives data, however, the default value is overridden with the value provided at the port. Thus, this object functions like a parameter and a port. The current value of the PortParameter is accessed like that of any other parameter. Its current value will be either the default or the value most recently received on the port.
A PortParameter might be contained by an atomic actor or a composite actor. To put one in a composite actor, drag it into a model from the utilities library, as shown in figure
3.2. The resulting icon is actually a combination of two icons, one representing the port, and the other representing the parameter. These can be moved separately, but doing so might create confusion, so we recommend selecting both by clicking and dragging over the pair and moving both together.
To be useful, a PortParameter has to be given a name (the default name, "portParameter," is not very compelling). To change the name, right click on the icon and select "Customize Name," as shown in figure 3.2. In the figure, the name is set to "noiseLevel." Then set the default value by either double clicking or selecting "Configure." In the figure, the default value is set to 10.0.
An example of a library actor that uses a PortParameter is the Sinewave actor, which is found in the sources library in Vergil. It is shown in figure
3.3. If you double click on this actor, you can set the default values for frequency and phase. But both of these values can also be set by the corresponding ports, which are shown with grey fill.
3.3.3 String Parameters
Some parameters have values that are always strings of characters. Such parameters support a simple string substitution mechanism where the value of the string can reference other parameters in scope by name using the syntax $name, where name is the name of the parameter in scope. For example, the StringCompare actor in figure3.4 has as the value of firstString "The answer is $PI". This references the built-in constant PI. The value of secondString is "The answer is 3.1415926535898". As shown in the figure, these two strings are deemed to be equal because $PI is replaced with the value of PI.
3.3.4 Expression Actor
The Expression actor is a particularly useful actor found in the math library. By default, it has one output and no inputs, as shown in Figure3.5(a). The first step in using it is to add ports, as shown in (b) and (c), resulting in a new icon as shown in (d). Note: In (c) when you click on Add, you will be prompted for a Name (pick one) and a Class. Leave the Class entry blank and click OK. You then specify an expression using the port names, as shown in (e), resulting in the icon shown in (f).
3.3.5 State Machines
Expressions give the guards for state transitions, as well as the values used in actions that produce outputs and actions that set values of parameters in the refinements of destination states. This mechanism was explained in the previous chapter.
1 The exceptions are parameters that are strictly string parameters, in which case the value of the parameter is the literal string, not the string interpreted as an expression, as for example the function parameter of the TrigFunction actor, which can take on only "sin," "cos," "tan", "asin", "acos", and "atan" as values.
![]() |
![]() |
![]() |