Trajexia system
PROGRAMMING MANUAL
26
Revi
si
on 3.0
more tasks, but care must be taken to avoid more than one program writing
to the same variable at the same time. The controller has 1024 global
variables, VR(0) to VR(1023). The variables are read and written using the
VR
command.
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 255 local variables can be declared. Only the first 16
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 15 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:
/i
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
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:
The TABLE and VR data can be accessed from the differ-
ent running tasks. When using either VR or TABLE varia-
bles, 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.
start:
FOR a = 1 to 100
MOVE(a)
WAIT IDLE
NEXT a
GOTO start
start:
a=0
REPEAT
a = a + 1
PRINT a
UNTIL a = 300
GOTO start
start:
GOSUB Initial
VR(length) = x
...
...
Initial:
length = 3
RETURN
start:
GOSUB Initial
MOVE(VR(length))
PRINT(VR(length))
...
Initial:
length = 3
RETURN
I52E-EN-03.book Seite 26 Freitag, 29. Juni 2007 11:55 11