Command: Expression (113)

Supported Axes:

All

 

See the Commands Overview topic for basic command information and how to issue commands from PLCs, HMIs, etc.

Command Parameters

#

Parameter Description

1

Expression

Description

This command can only be used in User Programs. It runs the Expression as entered by the user. Each expression command can contain multiple assignments, multiple lines, branching using IF statements, local variables, and can include comments.

This command is very versatile and can be used for such things as:

Step-Local Variables

The Expression (113) command can be used together with step-local variables. These are variables that are declared within a user program step, and can only be accessed from that step and are valid only for the execution of the step. For complex expressions, using local variables can significantly reduce the number of variables needed in the variable table.

Examples

Example 1

Adds 2 to the square root of Num2 and assigns the result to Num1.

 

// Calculate 2 plus the square root of Num2, and save it in Num1.

Num1 := 2.0 +SQRT(Num2);

 

 

Example 2

The first line adds 2.56 to the Actual Position and assigns the result to the Position Offset.

The second line divides the minimum value of Axis 0 or Axis 1 Actual Position by 2, adds 6, and assigns the result to the variable SampleVariable.

 

// Set the axis 0 Position Offset parameter to the current Actual

// Position plus 2.56.

_Axis[0].PosOffset:=_Axis[0].ActPos+ 2.56;

 

// Calculate 6 plus half the minimum of the first two axes current Actual

// positions. Save this in SampleVariable.

SampleVariable := Min(_Axis[0].ActPos,_Axis[1].ActPos) / 2.0 + 6.0;           

 

 

Example 3

An IF statement.

 

IF_Axis[0].StatusBits.InPos = TrueTHEN

MyREAL1 := 34.0;

MyREAL2 := 70023.0;

ELSIFABS(_Axis[0].ActPos) > 20.0 THEN

%QX0.1 := True;

ELSE

MyDINT := 2;

END_IF

 

 

Example 4

A COPY function. The variable i must be a DINT.

 

COPY(MyArray[0],MyOtherArray[i],20);

 

 

Example 5

Commenting a large section of code. You may wish to comment out a large section of code temporarily during development. The commented text will not be executed.

 

IF_Axis[0].StatusBits.InPos = TrueTHEN

MyREAL1 := 34.0;

MyREAL2 := 70023.0;

(*

ELSIF ABS(_Axis[0].ActPos) > 20.0 THEN

%QX0.1 := True;

*)

ELSE

MyDINT := 2;

END_IF

Entering an Expression

For a full description of building expressions, see the Expressions Overview topic.

Data Types

Expressions follow a strict data type convention. If you mix data types in an expression, you must use the type conversion functions. Note that "3" can be either a DINT or REAL type, but "3.0" is only REAL type.

Order of Execution

Within a Step

Items in a step are always executed in order starting from the top. Therefore, the Expression command is executed at the point it appears in a step in a user program. If the Expression command assigns a value to a register, that register will take on that value immediately. If that register is used in any following commands in the step, the register will use the value that it was assigned.

Within the Expression Command

Statements in an Expression are executed in order starting from the top.

Logging Results

The RMC logs the results of assignments and copies in the Expression (113) command to the Event Log for ease of troubleshooting. Logging does require significant processing time. If your user programs exceed the allotted execution time, one method of reducing the execution time is to disable expression logging. This will increase the amount of logic that fits in each user program step.

To disable expression logging, in the Programming Properties dialog, in the Verify tab, uncheck Log Expression Statements. With expression logging disabled, you can still use the LOG_EVENT function to log specific items.

For more details on reducing user program execution time, see Program Capacity and Time Usage.

 

See Also

Expressions Overview | List of Commands | Commands Overview


Send comments on this topic.

Copyright © 2024 Delta Computer Systems, Inc. dba Delta Motion