Omron TJ2-MC64 - PROGRAMMING Programming Manual page 17

Hide thumbs Also See for TJ2-MC64 - PROGRAMMING:
Table of Contents

Advertisement

Trajexia system
Note
The TABLE and VR data can be accessed from the different run-
ning tasks. When using either VR or TABLE variables, make sure
to use only one task to write to one particular variable. This to
avoid problems of two program tasks writing unexpectedly to one
variable.
Local variables
Named variables or local variables can be declared in programs and are
local to the task. This means that two or more programs running on different
tasks can use the same variable name, but their values can be different.
Local variables cannot be read from any task except for the one in which
they are declared. Local variables are always cleared when a program is
started. The local variables can be cleared by using either the CLEAR or the
RESET command.
A maximum of 1024 local variables can be declared. Only the first 32
characters of the name are significant. Undefined local variables will return
zero. Local variables cannot be declared on the command line.
Labels
The BASIC programs are executed in descending order through the lines.
Labels can be used to alter this execution flow using the BASIC commands
GOTO and GOSUB. To define a label it must appear as the first statement
on a line and it must be ended by a colon (:). Labels can be character strings
of any length, but only the first 32 characters are significant.
Using variables and labels
Each task has its own local labels and local variables. For example, consider
the two programs shown below:
PROGRAMMING MANUAL
/i
start:
FOR a = 1 to 100
MOVE(a)
WAIT IDLE
NEXT a
GOTO start
These two programs when run simultaneously in different tasks and have
their own version of variable a and label start.
If you need to hold data in common between two or more programs, VR
variables should be used. Or alternatively if the large amount of data is to be
held, the TABLE memory can be used.
To make a program more readable when using a global VR variable, two
approaches can be taken. The first is using a named local variable as a
constant in the VR variable. The local constant variable, however, must be
declared in each program using the global VR variable. Using this approach,
the example below shows how to use VR(3) to hold a length parameter
common for several programs:
/i
start:
GOSUB Initial
VR(length) = x
...
...
Initial:
length = 3
RETURN
The other approach is even more readable and uses the GLOBAL
command to declare the name as a reference to one of the global VR
variables. The name can then be used from within the program containing
the GLOBAL definition and all other programs. Take care that the program
containing the GLOBAL definition must be run before the name is used in
other programs. The best practice is to define global names in the start-up
program. Using this approach, the example above becomes:
start:
a=0
REPEAT
a = a + 1
PRINT a
UNTIL a = 300
GOTO start
start:
GOSUB Initial
MOVE(VR(length))
PRINT(VR(length))
...
Initial:
length = 3
RETURN
11

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Tj1-prtTj1-drtTj1-cortTj1-mlGrt1-ml2Tj1-fl02

Table of Contents