Basic programming guide – Remote Processing BASIC for the CX-10 Modbus User Manual

Page 6

Advertising
background image

BASIC PROGRAMMING GUIDE

1-3

Downloading a program requires transmitting an
ASCII file. As you type in (or download) a line,
Basic tokenizes that line. The time to do this
depends upon its complexity and how many lines of
code have been entered.

Basic must finish compiling a line before starting
the next one. When a line is compiled, a ">"
character is sent. This should be your terminal
programs pacing character when downloading a
program.

If your communications program cannot look for a
pacing prompt, set it to delay transmission after each
line is sent. A 100 ms delay is usually adequate, but
your program may be long and complex and require
more time. A result of short transmission time is
missing or incomplete program lines.

A technique used to further program documentation
and reduce code space is the use of comments
(REM) in a downloaded file. For example, you
could have the following in a file written on your
editor:

REM Check position

REM Read output from the pot and
REM calculate the position

2200 a = ain(0) :REM Get position

The first 3 comments downloaded to the card
are ignored. Similarly, the empty lines between
comments are also ignored. Line 2200, with its
comment, is a part of the program and could be
listed. The major penalty by writing a program this
way is increased download time.

Notice that you can write a program in lower case
characters. Basic translates them to upper case.

Some programmers put "NEW" as the first line in
the file. During debugging, it is common to insert
"temporary" lines. This ensures that these lines are
gone. Downloading time is increased when the old
program is still present.

If you like to write programs in separate modules,
you can download them separately. Modules are
assigned blocks of line numbers. Start up code
might be from 1 to 999. Interrupt handling (keypad,
serial ports) might be from lines 1000 to 1499.
Display output might be from 1500 to 2500. The

programmer must determine the number of lines
required for each section.

Basic automatically formats a line for minimum
code space. For example, you could download the
following line of code:

10 fora=0to5

When you listed this line, it would appear as:

10 FOR A=0 TO 5

Spaces are displayed but not stored. The following
line:

10 for a

=

0

to

5

would be compressed and displayed as in the second
example above. Spaces are removed. However,
spaces as part of a remark or PRINT are not
removed.

Basic contains no line renumbering capability.

Basic contains a rudimentary line editor which
allows editing a program line until a carriage return
is sent. The rubout or backspace key can be used to
delete characters working backwards form the
current character. After a line is entered, it cannot
be edited; you must enter an entire new line.
Deleting an undesired line is done by typing the line
number followed by a carriage return. Basic
automatically deletes all such lines.

Uppercase/Lowercase
Basic is generally not case-sensitive. Program or
command lines may be entered in lowercase or
uppercase; however they are (with some exceptions)
converted to uppercase. The case of text in remarks
and strings is preserved.

Variables and Constants
More than 25,000 unique variable or constant names
may be defined. Names may be up to eight
characters in length and must begin with a letter
between A-Z (no numbers or special characters).
The rest of the name may contain numbers or letters
and include the underline character.

All numeric variables are floating point. Variables
cannot be declared as integer or double precision.
Basic supports eight digits plus sign and exponent.
Extra digits are simply discarded. The range of
valid values is ± 1E-127 to ±0.99999999E+127.

Advertising