User guide

Chapter 1. Programming Fundamentals
19
Stand-Alone Products
:
All 3 types of variables
are automatically storied
in non-volatile memory.
6270: Numeric and string
variables may be
displayed with the RP240
(see page 133).
Binary variables can be used to store 32-bit binary or hexadecimal values. Binary variables can
also store I/O, system, axis, or error status (e.g., the VARB2=IN.12 command assigns input
bit 12 to binary variable 2). Bitwise operations are performed using binary variables.
String variables are used to store message strings of 20 characters or less. These message
strings can be predefined error messages, user messages, etc. The programming example in
the Command Value Substitutions (page 6) demonstrates the use of a string variable.
Converting Between Binary and Numeric Variables
Using the Variable Type Conversion (VCVT) operator, you can convert numeric values to
binary values, and vice versa. The operation is a signed operation as the binary value is
interpreted as a two's complement number. Any don't cares (x) in a binary value is interpreted
as a zero (Ø).
If the mathematical statement's result is a numeric value, then VCVT converts binary values to
numeric values. If the statement's result is a binary value, then VCVT converts numeric
values to binary values.
Numeric to Binary
Example Description/Response
VAR1=-5 Set numeric variable value = -5
VARB1=VCVT(VAR1) Convert the numeric value to a binary value
VARB1 *VARB1=1101_1111_1111_1111_1111_1111_1111_1111
Binary to Numeric
Example Description/Response
VARB1=b0010_0110_0000_0000_0000_0000_0000_0000 Set binary variable = +100.0
VAR1=VCVT(VARB1) Convert binary value to numeric
VAR1 *VAR1=+100.0
Using Numeric Variables
Some Numeric Variable Operations Reduce Precision
The following operations reduce the precision of the return value: Division and Trigonometric
functions yield 5 decimal places; Square Root yields 3 decimal places; and Inverse
Trigonometric functions yield 2 decimal places.
Mathematical
Operations
The following examples demonstrate how to perform math operations with numeric variables.
Operator precedence occurs from left to right (e.g., VAR1=1+1+13 sets VAR1 to 9, not 5).
Addition (+)
Example Response
VAR1=5+5+5+5+5+5+5
VAR1 *VAR1=35.0
VAR23=1000.565
VAR11=VAR1+VAR23
VAR11 *VAR11=+1035.565
VAR1=VAR1+5
VAR1 *VAR1=+40.0
Subtraction (-)
Example Response
VAR3=20-10
VAR20=15.5
VAR3=VAR3-VAR20
VAR3 *VAR3=-5.5
Multiplication (*)
Example Response
VAR3=10
VAR3=VAR3*20
VAR3 *VAR3=+200.0