The System 5000™ Data Collection Platform contains a built-in BASIC interpreter (as of
firmware version 1.2.0) allowing for more complex operations on the data logger. Many
traditional BASIC commands and features have been combined with a new subset of operations
to create the Basic 5000 language. Basic 5000 is thus able to provide a familiar BASIC base
while also providing direct access to the hardware and operations of the System 5000™.
Basic Features
• Support for traditional BASIC constructs such as goto, gosub, and line numbers
• Both number and string variables, including single and multi-dimensional arrays
• Built-in string and variable processing functions
• Easy access to COM/Serial Ports using simple PRINT and INPUT commands
• Easy access to Log Files using simple PRINT and INPUT commands
• Structured programming commands including SWITCH-CASE statements, single
and multi-line IF-THEN statements and FOR, WHILE, REPEAT, and DO loops
• User-created subroutine/function support
• Ability to use a Basic program as either an Input or an Output for any Task
• Ability to execute a program in response to Network or Serial communication
• Ability to perform complex math operations using built in trigonometric and
logarithmic functions
• Ability to use a Basic program’s returned values within Outputs (Log File, GOES, etc)
• Ability to run a program in response to incoming RS-232 serial communication
• No le size limit on Basic programs
• No limit on number of Basic programs on the system
• Easily transportable, programs appear as individual les in the Data File Manager
• Ability to perform new measurements of any hardware on Inputs (Analog,
Digital, etc) as well as Outputs (4-20mA, Digital, etc)
• Ability to retrieve current and previously measured values of any Task
• Access to system variables including current date and time and all subsets
• Ability to perform complex math operations using built in trigonometric and
logarithmic functions
• Simple program customization via the touch screen interface
Basic Fundamentals
Understanding the available functions and commands as well as the overall operations and flow
of Basic 5000 is essential to its proper use within the System 5000™. Primary Basic 5000
concepts and examples are provided below, followed by a listing of all available commands and
functions. Each command is given a description and an example of its use.
3
BASIC FEATURES & FUNDAMENTALS
Program Execution
Basic Programs on the System 5000™ can be used as either Inputs or Outputs and operate in the
same manner, being executed according to their associated Task’s priority. The System 5000™’s
sequence of operations is as follows:
Process all Task Inputs (according to Task Priority)
Process all Task Outputs (according to Task Priority)
As Task Inputs are executed sequentially based on priority, when a Basic Input Program begins,
all Tasks with higher priorities will have newly measured values. Tasks with lower priorities,
however, will still contain the previous scan’s values as they have not been run yet.
Basic Output Programs, on the other hand, will have full access to all newly measured values as
all Task Inputs have been run prior to the first Task Output being called.
Error Handling
Basic 5000 programs are parsed and checked before and during execution. If any syntax errors
are found in the code, the Basic Program will be skipped and the System 5000™ will continue its
operations. If any runtime errors are found during execution, the program will exit at that point
and the System 5000™ will continue its operations.
To assist with troubleshooting a Basic program, the Basic Management and Basic Program
Input/Output screens contain a “Debug” mode that allows line by line execution of the chosen
Basic Program with detailed reporting of variables and all related output. Any errors that are
reported should be resolved before implementing the program into the System 5000™’s schedule.
Grammar
The examples provided below will follow certain patterns when presented. All Basic 5000
statements will be capitalized while all variables and strings may contain both uppercase and
lowercase lettering. Though this form is used, the Basic 5000 Interpreter is not case-sensitive
with respect to commands/statements (however, variables are case-sensitive). In other words, the
“PRINT”, “Print”, and “print” statements are all interpreted as valid PRINT commands.
PRINT “Hello World”
Print “Hello World”
print “Hello World”
4
Basic Features and Fundamentals
Comments
The REM statement (meaning remark) or apostrophe (“ ‘ ”) introduce a comment that extends to
the end of the line. Notice that though REM is a statement as well, it does not require a statement
separator (“:”) if used on the same line as another statement.
REM This is a comment
‘ This is also a comment
PRINT “Hello World” REM This is a valid comment
PRINT “Hello World” : REM This is a valid comment with a separator
PRINT “Hello World” ‘ This is also a valid comment
Variables, Strings and Arrays
Unlike the case-insensitive nature of Basic statements, variables and strings are uniquely
identified by their names. Thus “var” is understood to be different than “Var”.
var = 15.2
PRINT “var: “, var REM prints “var: 15.2”
PRINT “Var: “, Var REM prints “Var: 0”
String variables may be used and require a trailing “$”.
var$ = “Hello World”
PRINT “var$: “, var$ REM prints “var$: Hello World”
Traditional variables do not need to be declared before their first use. Number variables are
initialized to zero (“0”) while string variables are initialized to an empty string (“”). Arrays, on
the other hand, need to be created first using the ARRAY command. Array contents are
initialized to zeros or empty strings depending on their declaration type.
REM create a single-dimension, two element number array
ARRAY myArray(2)
PRINT myArray(1), “ “, myArray(2) REM prints “0 0”
Global Variables may also be used in Basic 5000. Variables created and used within programs,
by default, are local only to that program. To create and use Global Variables, the GLOBAL
keyword may be specied before a variable’s name. The value of the global variable will be
preserved between Basic programs and can be called and updated by any other Basic program.
REM Global_var records how many times the Basic program has been called
GLOBAL Global_var
Global_var = Global_var + 1 REM adds one to our global variable
5
BASIC FEATURES & FUNDAMENTALS
Control Statements and Loops
Basic 5000 supports traditional control statements such as GOTO and GOSUB as well as single
and multi-line IF-THEN statements and SWITCH-CASE statements. GOTO and GOSUB can
jump to labels or line numbers within the code. Line numbers may be used in the Basic program,
but they are not required.
Loops are also allowed using FOR, WHILE, REPEAT, and DO statements. BREAK statements
may be used to leave any of the previously mentioned loops while the CONTINUE command can
be used to begin the next iteration of a loop.
Operators
Traditional arithmetic, comparison, and logical operators are available for use within Basic and are
noted below (ordered by precedence):
Arithmetic:
^ (power)
- (unary minus)
* / % (integer modulus)
+ -
Comparison:
= ==
<><= >=
<> !=
Logical:
NOT
AND
OR
Math Functions
Basic 5000 provides a comprehensive list of math functions including logarithmic and
trigonometric functions. All trigonometric functions use radians. The following functions are
available: ABS, ACOS, ASIN, ATAN, CEIL, COS, EXP, FLOOR, FRAC, H377C, H377F, INT,
LN, LOG, MAX, MIN, MOD, RND, SGN, SIN, SQR, SQRT, TAN, XOR. Constants EULER
and PI are also available for use within Basic 5000 programs.
Subroutines
In order to ease the structure and flow of a Basic program, subroutines may be declared and used
to perform various operations. The separation of these subroutines allows a more procedural
approach to be taken within the code as well as simplify the reuse of segments of code in later
programs. These subroutines can accept multiple parameters, numbers or strings, and can
likewise return a number or a string, if desired. Subroutines are declared with the SUB command,
ended with the END SUB command, and return values using the RETURN command. Specific SUB
commands may also be used as special entry points for designated IO. See the
SUB command reference (1-60) for more information regarding these special cases.
REM Calculate the Volume of a Rectangle
height = 3
width = 4
depth = 5
volume = calc_volume(height, width, depth) REM sets volume to 60
SUB calc_volume(h, w, d)
6
vol = h * w * d
RETURN vol
END SUB
Basic Features and Fundamentals
File I/O
Files stored on the System 5000™’s local le system can be accessed for reading, writing, and
appending of data. The OPEN command allows files to be opened and assigned a number for
use throughout the program. Using the INPUT and PRINT commands with the le’s assigned
number allows Basic to read and write to the opened file. Other commands are also available
such as EOF, LINE INPUT, SEEK, and TELL for further manipulation of files.
Serial and Network I/O
Serial and Network (Ethernet) communication act much the same as File I/O. COM and Ethernet
Ports can be opened with the OPEN command and closed with the CLOSE command via an
assigned number, similar to File I/O. Using the INPUT and PRINT commands with the network
or serial port’s assigned number allows Basic to read and write to the opened port.
CHECKRETURN provides verification that a PRINT statement was successful. The FLUSH
command can also be used to clear the buffer on an individual port.
such as EOF, LINE INPUT, SEEK, and TELL for further manipulation of files.
Listening Ports
Both Serial and Network Ports may also be set to constantly listen for incoming communication.
Simple web pages, data retrieval, and DAMS-NT are a few benefits Listening Ports can provide.
The Listening Ports Setup found within the System Setup Communications tab of the System
5000TM enables the set up of these ports. Incoming communication from a listening port can
trigger various programs to respond. Basic programs can be very useful for customizing this
interaction. Examples of listening port communication can be found under the OPEN command
detailed later in this document.
Escape Sequences and Hex Values
Special escape sequences are
available for use within Basic. Nonprintable characters such as a tab or
newline can be created by a using a
backslash (“\”) followed by a single
letter or hex value sequence as
detailed to the right.
Hex values can be specifically
retrieved using the \xXX escape
sequence. For example, \x09
would be translated as a horizontal
tab and \x0A as a newline. Note that
hexadecimal numbers
need to be used (thus 0A is equivalent
to decimal number 10) in this format.
Escape
Sequences
\b808backspace
\t909horizontal tab
\n100Anewline
\v110Bvertical tab
\f120Cform feed
\r130Dcarriage return
\”3422double quote
\’3927single quote
\\925Cbackslash
\xXXN/AN/Ahex value
ASCII ValueHex ValueDescription
7
BASIC FEATURES & FUNDAMENTALS
String Processing
Basic 5000 provides a number of commands that allow for string manipulation and processing.
Functions that return string variables contain a trailing “$” whereas functions returning number
variables do not have a “$”. Functions such as LEFT$, MID$, and RIGHT$ can be used for
extracting parts of a string. Separating a string into usable sections can be done with TOKEN
and SPLIT. Converting strings to numbers and numbers to strings can be quickly accomplished
with the STR$ and VAL functions. The “+” operator may also be used to concatenate strings.
There are many other string functions available including ASC, CHR$, HEX$, INSTR, LEN,
LOWER$, MID$, UPPER$ that may be used to manipulate strings and their contents.
System 5000™ Integration
Built within Basic 5000 are a number of commands that allow greater access to both the
hardware and the software side of the System 5000™ . Most of these commands are identified
by their GET and SET prefixes:
GETDB: Retrieves system settings saved within the database
GETSDI: Sends an SDI command and retrieves the resulting response
GETTASK: Retrieves current and previously measured values of an existing Task
GETTIMESTAMP: Retrieves current and previous timestamps for measured Tasks
GETVALUE: Retrieves a new measurement from attached hardware
SETDB: Modifies system database settings
SETPOWER: Modifies hardware power settings
SETNETWORK: Modifies network (ethernet) settings
SETTASK: Modifies the most recent measured value of an existing Task
SETTIMESTAMP: Modifies the most recent timestamp for a measured Task
SETVALUE: Modifies current hardware settings
For further information on the above commands as well as examples of their use and valid
parameters for each, please refer to each of the respective commands on the following pages.
Installing Basic Programs
Basic 5000 programs can be easily installed by pressing the Add New Program function button
on the Basic Program Management screen found under System Setup’s Inputs & Outputs menu.
Simply select a displayed program on the Basic Program Install screen and press the Install
button. Programs must have a .bas extension to be shown under the Basic Program Install menu.
Once a program has been installed and/or set up, the program will become available within the
respective Input, Output, and Listening Port menus. To view the program’s properties, modify
the availability of the program, or change the name under which it appears, use the Basic
Program Management.
8
Basic Features and Fundamentals
Advanced Programming with Symbols
In order to provide greater flexibility and reusability of Basic Programs on the System 5000™ ,
an advanced subset of commands, known as Symbols, are available. These Symbols allow
program parameters to be modified and defined on a Task by Task basis through the touch screen
interface. A single program could potentially be used for multiple purposes with the use of these
Symbols. Symbols begin with an apostrophe(‘), causing their declaration to appear as a
comment, are case-sensitive (the declaration must be uppercase), and end with a colon(:). The
Symbol’s parameters are then specied after the colon.
The following Symbols are available:
‘NAME:
‘DESC:
‘GROUP:
‘IO:
‘VAR:
The ‘VAR: Symbol can be specified many times throughout the program and defines variables
that can be seen and modified through the touch screen interface of the System 5000™. The
remaining Symbols (‘NAME:, ‘DESC:, ‘GROUP:, and ‘IO:) should be specified only once in a
program and provide information about the program itself. All Symbols are optional and are not
required for a program to run properly. An example program can best illustrate their individual
purposes and syntax:
Filename: blink.bas
‘NAME: Blink Digital LED
‘DESC: An LED attached to ground and Digital Port 3
‘GROUP: None
‘IO: Output
‘VAR: blink_delay, 2.5
‘VAR: msg$, “Program Done”
‘VAR: time_skip$, “00:00:00”, STATIC
IF (time_skip$ != DATETIME(ALARM$)) THEN
SETVALUE DIGITAL3, 1
SLEEP blink_delay
SETVALUE DIGITAL3, 0
ENDIF
PRINT msg$
Beginning with the ‘NAME: Symbol, if it is specified, the string following is used as the I/O
Name seen through the Task Input and Output selection screens. If no ‘NAME: Symbol is found,
the program’s lename is used (e.g. blink.bas). The Name of a program can be modied through
the Basic Management screen after the program has been installed.
The ‘DESC: Symbol provides a simple description that is viewable via Basic Management and
can be helpful to explain the purpose of a program.
9
BASIC FEATURES & FUNDAMENTALS
The ‘GROUP: Symbol specifies where the Basic Program will appear in the Input/Output menus.
If not specified or listed without a name, the program will be added to a “Basic Programs”
grouping in the menus. The special case of “None” (case-sensitive and without quotes) may be
used to not add the Program to a group but rather list Program alongside the other Inputs and
Outputs. Any other name used will create and add the Basic Program to the given group name.
The Group may also be modified through the Basic Management screen.
The ‘IO: Symbol accepts the following parameters: Input, Output, Serial, and/or Network. Any
combination of the above may be used to declare where this Basic Program will appear in the
menus. If Input is specified, the program will be available as a selectable Input for a Task.
Output allows the program to be added as an Output. Serial and Network allow the program to
be used as a Listening Ports Program, available only to their respective setting. Once a program
has been installed, these settings may be modified through the Basic Management screen.
The ‘VAR: Symbol accepts up to three parameters with comma’s separating them. The rst is
the variable name. If the variable name contains a trailing dollar-sign ($), it is treated as a string.
The optional second parameter is the variable’s default value. If a number variable is intended,
no quotes should be placed around the second parameter, however if a string variable is declared
(with a trailing $), the second parameter should have quotations around the specified value. An
optional third parameter may be specified declaring a variable as STATIC. Unlike standard
(local) variables whose values are defined individually for each run of a program, STATIC
variables maintain the same initial value across all instances of a program. For example, if two
or more Tasks are set to run the same program, local variables may be set differently for each
Task. Static variables, however, will be initialized with the same values independent of the Task
running the program. Changing a static variable’s value within one Task will change that value
for all other Tasks running that same program. Variables declared using the ‘VAR: Symbol can
be manually adjusted through the touch screen interface menus and provide the real flexibility in
creating simple and easily configurable Basic 5000 programs.
10
BASIC COMMANDS
02 /
& FUNCTIONS
11
BASIC COMMANDS & FUNCTIONS
Basic 5000 uses a combination of commands and functions to allow more complex operations to
be performed on the System 5000™. Commands and functions can both return values, though
each is done in a different manner. Commands such as INPUT and GETTASK return values to
the variable specified last on the line, after a comma:
GETTASK “Batt”, a$ REM stores the value of the Batt Task in variable a$
Functions, on the other hand, list the variable first, using an equals operator (“=”) to retrieve the
calculated value:
a = DATETIME(TIME) REM stores the current time (HHMMSS) in variable a
Commands and Functions available to the Basic 5000 language are listed alphabetically below.
420MA
Used in conjunction with the GETVALUE command, 420MA retrieves the current setting of the
4-20mA current loop and stores the value in the given variable.
Used in conjunction with the SETVALUE command, 420MA specifies the 4-20mA current loop
to be set to the desired number.
Example:
GETVALUE 420MA, var REM stores the current 4-20mA setting from the
REM daughterboard in the var variable
slot$ = “SLOT2”
GETVALUE 420MA slot$, s$ REM stores the current 4-20mA setting from
REM Slot 2 in the s$ variable
SETVALUE 420MA, 12.5 REM sets the 4-20mA on the daughterboard to 12.5mA
a = 16.0
SETVALUE 420MA SLOT1, a+2 REM sets the 4-20mA on Slot 1 to 18mA (a+2)
5VREF
Used in conjunction with the GETPOWER command, 5VREF requests the current state of the
+5V Reference and stores the value in the given variable. A 1 is stored if On, 0 if Off.
Used in conjunction with the SETPOWER command, 5VREF specifies the +5 Volt Reference to
be turned on or off. Numbers greater than zero will turn the +5 Volt Reference On, and numbers
less than or equal to zero will turn the +5 Volt Reference Off.
GETPOWER 5VREF, var REM stores a 1 if On, 0 if Off for the 5V Reference
REM on the daughterboard in the var variable
GETPOWER 5VREF SLOT1, s$ REM stores a 1 if On, 0 if Off for the 5V Ref.
REM on the Slot 1 5V Ref in the s$ variable
SETPOWER 5VREF, 1 REM turns the +5V Reference on the daughterboard On
slot$ = “SLOT1”
12
a = 0
SETPOWER 5VREF slot$, a REM turns the +5V Reference on Slot 1 Off
Basic Commands and Functions
ABS (number)
Returns the absolute value of the given number.
var2 = ABS(100) REM stores 100 in the var2 variable
var = ABS(-2.5) REM stores 2.5 in the var variable
ACIN
Used in conjunction with the GETVALUE command, ACIN requests a new measurement to be
made on the AC-In port and stores the value in the given variable.
GETVALUE ACIN, var REM stores a new AC-In measurement from the
REM daughterboard in the var variable
GETVALUE ACIN SLOT1, s$ REM stores a new AC-In measurement from
REM Slot 1 in the s$ string variable
ACOS (number)
Returns the arc-cosine value of the given number.
var = ACOS(0) REM stores 1.5707 (PI/2) in the var variable
var2 = ACOS(0.5) REM stores 1.0472 (PI/3) in the var2 variable
ACTIVELED
Used in conjunction with the GETPOWER command, ACTIVELED requests the current state of
the Active LED on the top of the System 5000™ and stores the value in the given variable. A 1
is stored if On, 0 if Off.
Used in conjunction with the SETPOWER command, SETPOWER specifies the Active LED on
the top of the System 5000™ to be turned on or off. Numbers greater than zero will turn the
Active LED On, and numbers less than or equal to zero will turn the Active LED Off.
GETPOWER ACTIVELED, a REM stores 1 if On, 0 if Off for the Active LED
REM into the a variable
SETPOWER ACTIVELED, 1 REM turns the Active LED On
REM Turn off the Active LED if it is on
GETPOWER ACTIVELED, a REM retrieves the Active LED status
IF (a == 1) THEN
SETPOWER ACTIVELED, 0 REM turns the Active LED Off
ENDIF
13
BASIC COMMANDS & FUNCTIONS
ALARMS
A parameter to the DATETIME function returning a string representation of the most recent
triggered alarm time, formatted as “HH:MM:SS”.
var$ = DATETIME(ALARM$) REM stores the most recent alarm e.g. “05:00:00”
ANALOGX
Used in conjunction with the GETVALUE command, ANALOGX requests a new measurement
to be made on the specified Analog channel and stores the value in the given variable.
slot$ = “SLOT2”
GETVALUE ANALOG1, var REM stores a new Analog Channel 1 measurement
REM from the daughterboard in the var variable
GETVALUE ANALOG3 slot$, s$ REM stores a new Channel 3 measurement
REM from Slot 2 in the s$ string variable
AND
A logical operator used between two expressions in conditional statements (e.g. if, while, etc).
Returns TRUE if the left and right expressions are TRUE, otherwise FALSE is returned.
var = 100
IF (var > 0 AND var < 50) PRINT “Small” REM prints nothing
IF (var > 0 AND var < 150) PRINT “Large” REM prints “Large”
ARRAY
Declares and creates an array. Arrays may be single or multi-dimensional and filled with
numbers or strings. Number arrays, when created, are lled with zeros, while string arrays are
lled with empty strings (“”). To enlarge an arrays size (not its dimension), re-declare the array
with a larger size. Existing data will be preserved. Re-declaring an array with a smaller size
does nothing. ARRAYDIM and ARRAYSIZE can be used to determine the number of
dimensions of an array as well as the sizes of those respective dimensions.
Single-dimensional array:
ARRAY myArray(5)
FOR i = 1 TO 5
myArray(i) = i * 2 REM Duplicate the number’s value inside the array
NEXT i
REM myArray(i) now contains values 2 4 6 8 and 10
14
Basic Commands and Functions
Multi-dimensional array:
ARRAY myArray$(3,7) REM 2-dimensional string array (3 rows, 7 columns)
FOR i = 1 TO 3
FOR j = 1 TO 7
myArray$(i,j) = str$(i * j) REM str$ converts a number to a string
NEXT j
NEXT i
REM myArray$(i,j) now contains values 1 2 3 4 5 6 7
2 4 6 8 10 12 14
ARRAYDIM (array)
Returns the given array’s number of dimensions.
ARRAY myArray(10)
PRINT ARRAYDIM(myArray()) REM prints “1” as myArray is one-dimensional
ARRAY myArr(2,4,4)
PRINT ARRAYDIM(myArr()) REM prints “3” as myArr is three-dimensional
ARRAYSIZE (array, number)
Returns the given array’s dimension’s size, where array species the array and number species
the dimension. The last parameter is optional and defaults to the first dimension if not specified.
ARRAY myArray(10)
PRINT ARRAYSIZE(myArray()) REM prints “10”
ARRAY myArr$(2,4)
PRINT ARRAYSIZE(myArr$(), 2) REM prints “4”
ASC (string)
Returns the rst character’s ASCII numerical representation. CHR$( ), converting a numerical
value to the ASCII character, is the opposite function of ASC( ).
PRINT ASC(“A”) REM prints “65”
PRINT CHR$(65) REM prints “A”
ASIN (number)
Returns the arc-sine value of the given number.
var = ASIN(0) REM stores 0 in the var variable
PRINT ASIN(1) REM prints “1.5708” (PI/2)
15
BASIC COMMANDS & FUNCTIONS
ATAN
Returns the arc-tangent value of the given number.
var = ATAN(0) REM stores 0 in the var variable
PRINT ATAN(1) REM prints “0.785398” (PI/4)
BATT
Used in conjunction with the GETVALUE command, BATT requests a new measurement to be
made of the attached battery and stores the value in the given variable.
GETVALUE BATT, var REM stores a new measurement of the attached
REM battery in the var variable
BREAK
Causes an immediate exit from a loop or SWITCH statement.
a = 0
WHILE (a < 10)
a = a + 1
IF (a > 5) BREAK REM the while loop exits once a > 5
WEND
REM variable a is now 6
CASE
Used with the SWITCH statement to list potential routes.
a$ = “Hi”
SWITCH a$
CASE “Hello”: PRINT “And Hello to you”
BREAK
CASE “Hi”: PRINT “Hi!” : BREAK REM prints “Hi!”
END SWITCH
CEIL
Returns the ceiling of the given number.
a = CEIL(1.2) REM stores 2 in the a variable
PRINT CEIL(4.7) REM prints “5”
16
Basic Commands and Functions
CHECKRETURN ( )
Returns the result (return value) of the most recent PRINT to either a serial or ethernet
connection. If an error has occurred, this number will be less than zero. A successful PRINT
returns the number of characters written to the open connection. This may be most useful for
detecting disconnected serial or network ports.
PRINT CEIL(4.7) REM prints “5”
OPEN
CHR$ (number)
Returns the number’s ASCII character representation. ASC( ), converting a character to its ASCII
numerical value, is the opposite function of CHR$( ).
PRINT CHR$(65) REM prints “A”
PRINT ASC(“A”) REM prints “65”
CLEARSDI ( )
Clears the current time period’s SDI-12 cache. Using prior to a GETVALUE SDIXX command
forces the GETVALUE command to retrieve new SDI-12 measurements.
CLEARSDI() REM Clear any cached SDI values for this time period
GETVALUE SDI01, a1$ REM request a new measurement (address 0, param 1)
GETVALUE SDI02, a2$ REM retrieve the second parameter
CLEARSDI() REM Force our next request to be a new measurement
GETVALUE SDI01, b1$ REM request a new measurement (address 0, param 1)
CLOSE
Closes a file, serial/com port, or network/ethernet connection that has been previously opened
with the OPEN command.
OPEN “COM2” AS #9
CLOSE #9
OPEN “SiteID.csv” FOR APPENDING AS #1
CLOSE #1
OPEN “192.168.0.1:80” AS #4
CLOSE #4
17
BASIC COMMANDS & FUNCTIONS
CONTINUE
Used to begin the next iteration of a FOR, WHILE, REPEAT, or DO loop.
FOR var = 1 TO 10
IF (var = 5) CONTINUE REM “5” won’t be printed
PRINT “ “, var; REM prints “ 1 2 3 4 6 7 8 9 10”
REM Note: the semicolon removes the default new line (\n)
REM that appears at the end of a PRINT statement
NEXT var
COS (number)
Returns the cosine value of the given number.
var = COS(0) REM stores 1 in the var variable
PRINT COS(PI) REM prints “-1”
COUNTERX
Used in conjunction with the GETVALUE command, COUNTERX requests a new counter
measurement to be made on the specified digital port and stores the value in the given variable.
Used in conjunction with the SETVALUE command, COUNTERX specifies the counter on the
specified digital port to be set to the desired number. The counter will be set to the integer value
of the number if a floating point value is passed in.
GETVALUE COUNTER3, var REM stores a new Counter measurement of digital
REM port 3 from the daughterboard in the var
REM variable
slot$ = “SLOT1”
GETVALUE COUNTER4 slot$, s$ REM stores a new Counter measurement of
REM digital port 4 from Slot 1 in the s$
REM string variable
SETVALUE COUNTER2, 86 REM sets the Counter on Digital Port 2 on the
REM daughterboard to 86
a = 23.05
SETVALUE COUNTER1 SLOT2, a+2 REM sets the Counter on Digital Port 1 on
REM Slot 1 to 25 (INT(a+2))
DATE
A parameter to the DATETIME function returning a six-digit number representation of the
current date, formatted as YYMMDD.
var = DATETIME(DATE) REM stores 91231, inferring Dec 31, 2009
18
Basic Commands and Functions
DATE$
A parameter to the DATETIME function returning a string representation of the current date,
formatted according to the System 5000 Settings (default is “MM/DD/YYYY”).
var$ = DATETIME(DATE$) REM stores “12/31/2009”, inferring Dec 31, 2009
DATETIME
Used to retrieve the current date, time, subset thereof, or alarm time. Available parameters are
DATE, DATE$, DAY, JDAY, MONTH, YEAR, TIME, TIME$, SECONDS, MINUTES,
HOURS, EPOCH, EPOCHDAY, and ALARM$. DATE and TIME return integer values of the
current date and time formatted as YYMMDD and HHMMSS respectively. The DATE$ and
TIME$ parameters return a similar format as string values, specifically “MM/DD/YYYY”
according to the System 5000™ Date Format setting and “HH:MM:SS” respectively. The
ALARM$ parameter returns the most recent triggered alarm time, returned as a string formatted
as “HH:MM:SS”.
SECONDS, MINUTES, HOURS, DAY, MONTH, and YEAR each return a two-digit integer
value of the specified current date or time subsection. JDAY returns a three-digit integer value
of the Julian Day. EPOCH returns an integer value of the number of seconds since 00:00:00 Jan
1, 1970 while EPOCHDAY returns the number of seconds from 00:00:00 Jan 1, 1970 until the
start of today’s date at 00:00:00.
var = DATETIME(DATE) REM stores 91231, inferring Dec 31, 2009
var$ = DATETIME(TIME$) REM stores the current time, e.g. “12:00:20”
DAY
A parameter to the DATETIME function returning the current day as a number, formatted as DD.
var = DATETIME(DAY) REM stores 16, inferring the 16th day
DEFAULT
Used within a SWITCH-CASE statement to mark the default route if no other CASE statements are matched.
var = MINUTES
SWITCH var
CASE 0: PRINT “Top of the hour” : BREAK
CASE 15: PRINT “15 Minutes Past” : BREAK
CASE 30: PRINT “Half Past” : BREAK
CASE 45: PRINT “45 Minutes Past” : BREAK
DEFAULT: PRINT “Not a 15-minute interval” : BREAK
END SWITCH
19
BASIC COMMANDS & FUNCTIONS
DELAY
Causes the program to pause execution for the specified number of seconds. A decimal number
may be used to specify more specific and smaller time increments (e.g. milliseconds). SLEEP
and DELAY are identical commands.
SLEEP 2.5 REM pauses the program for 2.5 seconds
DELAY 0.25 REM pauses the program for 0.25 seconds
DIFFXX
Used in conjunction with the GETVALUE command, DIFFXX requests a new measurement to
be made on the specified Differential (Analog) channels and stores the value in the given
variable.
REM of Analog channels 1-2 in the var variable
GETVALUE DIFF78 SLOT2, s$ REM stores a new Differential Channel
REM measurement of Analog channels 7-8 from
REM Slot 1 in the s$ string variable
GETVALUE DIFF12, var REM stores a new Differential Channel measurement
DIGITALX
Used in conjunction with the GETVALUE command, DIGITALX requests a new level
measurement to be made on the specified Digital port and stores the value in the given variable.
Used in conjunction with the SETVALUE command, DIGITALX specifies the Level on the
specied digital port to be set to the desired number. Numbers greater than zero will set the port
high (1), and numbers less than or equal to zero will set the port low (0).
GETVALUE DIGITAL4, var REM stores a new Level measurement of digital
REM port 4 from the daughterboard in the var
REM variable
GETVALUE DIGITAL2 SLOT1, s$ REM stores a new Level measurement of
REM digital port 2 from Slot 1 in the
REM s$ string variable
slot$ = “SLOT3”
SETVALUE DIGITAL2, 12.5 REM sets high Digital port 2 on the daughterboard
a = 0
SETVALUE DIGITAL1 slot$, a REM sets low Digital port 1 on Slot 3
20
Basic Commands and Functions
DNS
Used in conjunction with the SETNETWORK command, DNS will find or set the Domain
Nameservers to use for the network. Available parameters are AUTO or MANUAL. AUTO will
automatically find the nameservers (performed when the IP AUTO command is issued);
MANUAL sets the given parameter as the Preferred DNS. If another DNS MANUAL entry is
given, that entry will become the Preferred DNS, and the previous entry will move to the
Alternate DNS position.
SETNETWORK DNS AUTO
SETNETWORK DNS MANUAL, “192.168.0.6” REM set as Alternate DNS
SETNETWORK DNS MANUAL, “192.168.0.5” REM set as Preferred DNS
DO
Begins an infinite loop encompassed by DO and LOOP. A BREAK or GOTO statement may be
used to leave the loop.
DO
REM Break out of the loop when our seconds are greater than 30
x = DATETIME(SECONDS)
IF (x > 30) BREAK
LOOP
ELSE
Optionally used as part of an IF statement to indicate a default branch if no other conditions are
evaluated as true.
var = 16
IF (var >= 21) THEN
PRINT “Adult”
ELSE
PRINT “Not Adult” REM prints “Not Adult”
ENDIF
ELSEIF
Optionally used as part of an IF statement to indicate another condition to evaluate. The option is
only evaluated if all previous options have resulted in FALSE.
var = 16
IF (var >= 21) THEN
PRINT “Adult”
ELSEIF (var >= 13) THEN
PRINT “Teen” REM prints “Teen”
ELSE
PRINT “Not Adult”
ENDIF
21
BASIC COMMANDS & FUNCTIONS
END
Immediately ends the Basic program. Optional if used as the last statement.
var = 12
IF (var > 10) THEN
var = 5
END
ENDIF
var = 10 REM never reached as program has ended (var still equals 5)
ENDIF
Declares the end of a multi-line IF-THEN statement. Not required on single-line if statements.
var = 16
IF (var >= 21) THEN
PRINT “Adult”
ELSEIF (var >= 13) THEN
PRINT “Teen” REM prints “Teen”
ELSE
PRINT “Child”
ENDIF
END SUB
Declares the end of a subroutine (begun with the SUB statement).
volume = calc_volume(3, 4, 5) REM volume contains 60
SUB calc_volume(h, w, d)
vol = h * w * d
RETURN vol
END SUB
EOF (filenumber)
Returns true if the given filenumber has reached the end of the file, false if there is still data
available to be read from the current position.
OPEN “SiteID.csv” FOR READING AS #1
WHILE (NOT EOF(#1))
LINE INPUT #1, var$
PRINT var$ REM prints the contents of SiteID.csv one line at a time
WEND
22
CLOSE #1
Basic Commands and Functions
EPOCH
A parameter to the DATETIME function returning the number of seconds elapsed since Jan 1, 1970
00:00:00.
var = DATETIME(EPOCH) REM stores 1893300182
EPOCHDAY
A parameter to the DATETIME function returning the number of seconds elapsed fromJan 1, 1970
00:00:00 until today’s date at 00:00:00.
var = DATETIME(EPOCHDAY) REM stores 1893283200
ERROR
Ends the Basic program with a custom error message. Primarily intended for troubleshooting Basic
programs.
var = 12
IF (var > 10) THEN
ERROR “Number too large - this shouldn’t happen!”
ENDIF
PRINT “Already Ended” REM never prints as program has ended
ERRORSTR
Used in conjunction with the GETDB command, ERRORSTR requests the System 5000™’s Default
Error String as specified in the System Settings screen and stores it in the given string variable. This
value defaults to -99.99.
GETDB ERRORSTR, var$ REM stores the Default Error String in var$
ETHERNET
Used in conjunction with the GETPOWER command, ETHERNET requests the current state of the
Ethernet port (10/100 BaseT) and stores the value in the given variable. A 1 is stored if On, 0 if Off.
Used in conjunction with the SETPOWER command, ETHERNET specifies the Ethernet port (10/100
BaseT) to Ethernet port On, and numbers less than or equal to zero will turn the Switched +12 Volt
Off.
Used as a parameter to the OPEN command, attaches to the listening port associated with the
program. This parameter has been deprecated and replaced with the LISTENER parameter. See
LISTENER and the OPEN command below for more information.
23
BASIC COMMANDS & FUNCTIONS
GETPOWER ETHERNET, var REM stores a 1 if On, 0 if Off for the Ethernet
REM port on the daughterboard in the var variable
SETPOWER ETHERNET, 0 REM turns the Ethernet port Off
a = 16.0
SETPOWER ETHERNET, a REM turns the Ethernet Port On
EULER
A read-only constant containing the number 2.7182818284590452.
var = EULER REM contains 2.71828
EXP (number)
Returns e raised to the power of the given number. Identical to EULER^number.
var = EXP(0) REM stores 1, equivalent to EULER^0
var = EXP(1) REM stores 2.71828, equivalent to EULER^1
var = EULER^2 REM stores 7.38906, equivalent to EXP(2)
FALSE
A read-only constant containing the number 0.
var = 0
IF (var = FALSE) GOTO 50 REM jumps to line 50 of the program
FLOOR
Returns the floor of the given number.
a = FLOOR(1.2) REM stores 1 in the a variable
a = FLOOR(4.7) REM stores 4 in the a variable
FLUSH
For files, writes any remaining unwritten (buffered) data to the specified file. For serial and ethernet
ports, removes any extra data on the given line. Closing a file, serial, or ethernet port causes an
automatic flush to occur.
OPEN “COM 2” AS #2
INPUT #2, a$ REM retrieves from COM2 and stores in string a$
PRINT #2 “a1”
FLUSH #2
INPUT #2, b$ REM retrieves from COM2 and stores in string b$
CLOSE #2
OPEN “SiteID.csv” FOR READING AS #1
INPUT #1, a$ REM retrieves from COM2 and stores in string a$
24
FLUSH #1
INPUT #1, b$ REM retrieves from COM2 and stores in string b$
CLOSE #1
Basic Commands and Functions
FOR
Begins a for loop encompassed by FOR and NEXT with an optional STEP parameter (default STEP
is 1, negative STEPs may be used).
FOR x = 1 TO 5
PRINT x * x, “ “; REM prints “1 3 9 16 25 “
NEXT x
FOR a = 10 TO 1 STEP -2
PRINT “ “, a; REM prints “ 10 8 6 4 2”
NEXT a
FRAC (number)
Returns the fractional part of the given number.
var = 26.245 REM stores 0.245 in var
FREQUENCYX
Used in conjunction with the GETVALUE command, FREQUENCYX requests a new frequency
measurement to be made on the specified Digital port and stores the value in the given variable.
slot$ = “SLOT1”
GETVALUE FREQUENCY1, var REM stores a new frequency measurement of
REM digital port 1 from the daughterboard in
REM the var variable
GETVALUE FREQUENCY2 slot$, s$ REM stores a new frequency measurement of
REM digital port 2 from Slot 1 in the
REM s$ string variable
GATEWAY
Used in conjunction with the SETNETWORK command, GATEWAY sets the given parameter as the
Gateway address to use for the network. A specified gateway should be given after the IP MANUAL
and NETMASK commands have been issued.
SETNETWORK GATEWAY, “192.168.0.1”
GETDB
Used to retrieve a system database value. The response is stored in the last variable provided.
Available parameters are ERRORSTR, SITEID, SCANRATE with a given Task, and TASKNAME.
ERRORSTR returns the Default Error String (default is -99.99). SITEID returns the System 5000™’s
Site ID, SCANRTE returns the Scan Rate of the given Task as a measurement of seconds, and
TASKNAME returns the calling Task’s name (if the program is run as an Input or Output) or the
Default Error String (if not run as a Task I/O).
25
BASIC COMMANDS & FUNCTIONS
GETDB ERRORSTR, var$ REM stores the Default Error String in var$
GETDB SITEID, var$ REM stores the System 5000 Site ID in var$
task$ = “myTask”
GETDB SCANRATE task$, A REM stores the Scan Rate for myTask in A
GETDB TASKNAME, name$ REM stores the calling Task’s name in name$
GETPOWER
Used to retrieve the on/off status for a powered piece of hardware. Available parameters are
ACTIVELED (Active LED), ETHERNET (10/100 BaseT), SW12V (Switched +12V) , and the 5VREF (+5V
Reference) whose status’ can be read, returning a 1 for On or 0 for Off.
GETPOWER ACTIVELED, var REM stores the status of the Active LED in var
GETPOWER ETHERNET,var REM stores the status of the Ethernet port in var
GETPOWER SW12V, var REM stores the status of the Switched +12V in var
GETPOWER 5VREF SLOT1, var REM stores the status of the +5V Ref in var
GETSDI
Used to send a command and retrieve its response on the SDI-12 bus. The given command can
optionally contain the trailing exclamation point (“!”) and automatically performs retries. The
response is stored in the last variable provided. If no response is found, and System 5000™
Default Error String (default is -99.99) is returned. No caching of commands or responses is
performed.
REM Retrieve the second measurement parameter from an SDI-12 sensor
REM SDI Measurement commands return 5 characters (atttn)
REM a = sensor address, t = seconds to measure, n = # of measurements
GETSDI “0M!”, var$ REM returns 00022
delay_time$ = mid$(var$, 2, 3) REM stores 002 in delay_time$
delay_time = val(delay_time$) REM stores 2 in delay_time
DELAY delay_time REM waits for 2 seconds
sdi_cmd$ = “0D0!”
GETSDI sdi_cmd$, var$ REM returns 0+2.941+.012
var$ = mid$(var$, 2) REM saves +2.941+.012 in var$
ARRAY arr$(1) REM declare our array for use with TOKEN
result = TOKEN(var$, arr$(), “+-”) REM separate based on + or FOR param = 1 TO result REM result = 2
IF (param == 2) THEN
var2$ = arr$(param)
END IF
NEXT param
26
PRINT var2$ REM prints .012
Basic Commands and Functions
GETTASK
Returns the provided Task’s most recent measured value. If an unknown Task is specied,
the System 5000™ Default Error String (default is -99.99) is returned. If previous a Task/scan
measurement is desired, an additional parameter may be specified prior to the last variable. A “1”
indicates the most recent scan, “2” indicates the previous scan, “3” indicates three scans prior, etc.
GETTASK “myTask”, var
PRINT var REM prints “0.023”, as myTask currently measures Analog 1
REM Average the last four scans
task$ = “myTask”
FOR i = 1 to 4
GETTASK task$ i, tempVal
avg = avg + tempVal
NEXT i
avg = avg/4
PRINT “myTask avg: “, avg REM prints the average of the last four scans
GETTIMESTAMP
Returns the provided Task’s most recent measured value timestamp formatted according to the
system setup (default is MM/DD/YYYY HH:MM:SS). If an unknown Task is specified, the System
5000™ Default Error String (default is -99.99) is returned. If previous a Task/scan measurement
timestamp is desired, an additional parameter may be specified prior to the last variable. A “1”
indicates the most recent scan timestamp, “2” indicates the previous scan timestamp, “3” indicates
three scans prior timestamp, etc.
GETTASK “myTask”, var
GETTIMESTAMP “myTask”, var_time$
PRINT var_time$, “ “, var REM prints the timestamp and value of myTask
GETVALUE
Used to request a new measurement from the System 5000™. Available parameters are ACIN
(AC-In), ANALOGX (Analog), DIFFXX (Differential), BATT (Battery), DIGITALX (Digital Port Level),
FREQUENCYX (Frequency), COUNTERX (Event Counter), QUADXX (Quadrature Counter), SDIXX
or SDIXXX, TEMP (Internal Temperature), and 420MA (4-20mA Output). For analog and digital
measurements, X is a number indicating the requested port or channel. An optional SLOTX may
be specified for option cards (if not, the daughterboard is presumed). For SDI measurements, the
first X is the sensor address, the remaining X or XX is the requested parameter number. An optional
string may follow the SDI request specifying a measurement type, which if not specified, defaults
to “M”. Note that SDI-12 performs caching on measurement commands. Thus if a measurement
has already been requested for that time period, the previous values will be returned (rather than
requesting a new measurement). To force a new measurement, use the CLEARSDI( ) function to
clear the SDI cache. Lastly, a variable (either string or number) must be specified to store the
result. If an error is encountered the System 5000™ Default Error String (default is -99.99)
is returned.
27
BASIC COMMANDS & FUNCTIONS
slot$ = “SLOT2”
GETVALUE DIFF34, var REM stores a new quadrature counter measurement of
REM ports 3-4 from the daughterboard in the var
REM variable
GETVALUE ANALOG1 slot$, s$ REM stores a new analog measurement of
REM channel 1 from Slot 2 in the s$ string
REM variable
CLEARSDI() REM Clear any cached SDI values for this time period
GETVALUE SDI01, a1$ REM request a new measurement (address 0, param 1)
GETVALUE SDI02, a2$ REM retrieve the second parameter
CLEARSDI() REM Force our next request to be a new measurement
GETVALUE SDI01, b1$ REM request a new measurement (address 0, param 1)
GLOBAL
Specifies a variable as being global and retrieves any previously stored value. A global variable
allows any Basic program access to retrieve, modify, or update the contents of the variable. Global
values are only retrieved if the variable is initialized with the GLOBAL keyword. Newly declared
global variables are initialized to 0 if they are a number or “” if they are a string. In similar fashion, to
delete a global variable, simply set its value to 0 if it is a number or “” if it is a string.
REM Maintain a running average of the Battery
GLOBAL Global_var
GETVALUE BATT, battVolt
REM If Global_var hasn’t been created, use our retrieved value
Branches to the specified label or line number within the program. Once a RETURN statement is
reached, execution is passed back to the statement immediately following GOSUB. Subroutines,
defined with the SUB command, provide a much more flexible method of executing and running
portions of code and should be used instead of GOSUB.
h = 3
w = 4
d = 5
GOSUB 100
GOSUB ComputeArea
PRINT “Area: “, area REM prints “Area: 12”
END
LABEL ComputeArea
area = h * w
RETURN
100
28
volume = h * w * d
PRINT “Volume: “, volume REM prints “Volume: 60”
RETURN
Basic Commands and Functions
GOTO
Jumps to the specified label or line number within the program. Unlike GOSUB, GOTO statements
never return back to the point of the GOTO and thus have no RETURN statement. Subroutines,
defined with the SUB command, cannot be exited with the GOTO statement.
REM Only prints “Volume: 60” as the GOSUB statement is never reached
h = 3
w = 4
d = 5
GOTO 100
GOSUB ComputeArea
PRINT “Area: “, area REM prints “Area: 12”
END
LABEL ComputeArea
area = h * w
RETURN
100
volume = h * w * d
PRINT “Volume: “, volume REM prints “Volume: 60”
H377C (number)
Returns the temperature, in degrees Celsius, of the given number (expecting a 0-5V analog
voltage reading) based on the math equation for the WaterLog model H-377 temperature probe.
var = H377C(3.25) REM stores 23.1499
H377F (number)
Returns the temperature, in degrees Fahrenheit, of the given number (expecting a 0-5V analog
voltage reading) based on the math equation for the WaterLog model H-377 temperature probe.
var = H377F(3.25) REM stores 73.6698
HEX$ (number)
Returns the ascii-hexadecimal representation of the given number as a string.
var = 32
hex_var$ = HEX$(var) REM stores “20”
HOURS
A parameter to the DATETIME function returning a two-digit number representation of the current
hour, formatted as HH.
29
var = DATETIME(HOURS) REM stores 5, inferring the 5th hour
BASIC COMMANDS & FUNCTIONS
IF
Used to take actions based on the evaluation of given conditional statements. True is determined
as anything non-zero; false is zero.
The short form of the IF statement does not include a THEN and must remain on one line.
Multi-line IF statements contain the THEN keyword as well as ENDIF to mark the ending of the
IF statement. IF statements may also contain the keywords ELSEIF to introduce alternative
conditional statements as well as the ELSE keyword to provide a default path if no other
conditions evaluate to true.
Single-line IF statement:
var = 250
IF (var >= 200) PRINT “Large number” REM prints “Large number”
Multi-line IF statement:
var = 250
IF (var >= 500) THEN
PRINT “Very Large number”
ELSEIF (var >= 250) THEN
PRINT “Large number” REM prints “Large number”
ELSE
PRINT “Small number”
ENDIF
INPUT
Read from a file, serial (COM) port, or network (ethernet) connection that has been previously
opened with the OPEN command. When used with a serial or network port, an additional variable
may be specified to set an optional timeout in milliseconds for reading from the port (default is
100ms). When used with a file or serial port, an optional delimiter (stop character) may be specified
for retrieving data. The default delimiter for files is a space; the end of transmission EOT (0x04)
character is used for serial communication. Network communication uses the line feed (0x0A) as
its stop character. Note that files will not return the stop character whereas serial communication
returns all characters (including the delimiter). Entire lines of
files can be retrieved using the LINE INPUT command.
OPEN “COM1” AS #3
INPUT #3 250, a$ REM sets this timeout to 250ms rather than 100ms
INPUT #3 “,” 250, b$ REM retrieve until a comma or 250ms passes
CLOSE #3
OPEN “SiteID.csv” FOR READING AS #1
INPUT #1, b$ REM retrieves characters until a space is found
INPUT #1 “\t”, b$ REM retrieves characters until a tab is found
INPUT #1 “,”, b$ REM retrieves characters until a comma is found
30
CLOSE #1
Basic Commands and Functions
INSTR (string, string, number)
Returns the position, starting at the position given by the third optional parameter (default is 1),
of the first occurrence of the second given string within the first given string beginning at the left.
Returns the position, starting at the position given by the third optional parameter (default is 1), of
the first occurrence of the second given string within the first given string beginning at the left.
var = INSTR(“Analog 2: 3.5, Digital 4: 1”, “Digital”) REM stores 16
var = INSTR(“Analog 1: 1.25, Analog 2: 2.5”, “Analog”, 2) REM stores 17
INT (number)
Returns the integer part of the given number.
var = INT(26.245) REM stores 26
IP
Used in conjunction with the SETNETWORK command, IP will find or set the Ethernet IP Address to
use for the network. Available parameters are AUTO or MANUAL. AUTO will automatically find an
IP Address (DHCP); MANUAL sets the given parameter as the IP Address.
SETNETWORK IP AUTO
SETNETWORK IP MANUAL, “192.168.0.82”
JDAY
A parameter to the DATETIME function returning the current calendar julian day as a number,
formatted as DDD.
var = DATETIME(JDAY) REM stores 57, inferring February 26th
LABEL
Identifies a specific location according to the given name. Commands such as GOTO and GOSUB
can refer to and send execution to named LABELs. Line numbers are simply a special case of
LABELs and are also supported.
h = 3
w = 4
d = 5
GOTO 100
LABEL ComputeArea
area = h * w
PRINT “Area: “, area REM prints “Area: 12”
RETURN
100
volume = h * w * d
PRINT “Volume: “, volume REM prints “Volume: 60”
GOSUB ComputeArea
END
31
BASIC COMMANDS & FUNCTIONS
LEFT$ (string, number)
Returns a string, starting from the left side, containing the given number of characters from the
given string.
OPEN “SiteID.csv” FOR APPENDING AS #1
LINE INPUT #1 b$ REM retrieves a single line and stores it in b$
CLOSE #1
LISTENER
Used as a parameter to the OPEN command, attaches to the listening port associated with the
program. The port can be either a serial (COM) port or network (Ethernet) port and is configured
using the touch screen interface under the Listening Ports Setup screen. Opening the Listener port
enables communication between the System 5000TM and the connecting device.
OPEN “LISTENER” AS #1
INPUT #1 “\r” 2000, cmd$ REM check for a command
IF (cmd$ == “Analog1”) THEN
GETVALUE ANALOG1, val
PRINT #1 “Analog1: “, val
ENDIF
CLOSE #1
LN (number)
Returns the natural logarithm of the given number. The LOG function should be used if a common
(base-10) logarithm is required.
var = LN(3) REM stores “1.09861”
var = LN(5) REM stores “1.60944”
32
Basic Commands and Functions
LOCAL
Used within a subroutine, LOCAL marks the given variable as valid only within that subroutine.
LOCAL var
var = 100
PRINT “var: “, var REM prints “var: 100”
END SUB
var = 10
change_var()
PRINT “var: “, var REM prints “var: 10” (would print 100 if not LOCAL)
SUB change_var()
LOG (number)
Returns the common (base-10) logarithm of the given number. The LN function should be used if a
natural logarithm is required.
var = LOG(5) REM stores “0.69897”
var = LOG(10) REM stores “1”
LOOP
Declares the end of a DO-LOOP statement.
DO
PRINT “ “, var; REM prints “ 0 1 2 3 4 5 6 7 8 9”
var = var + 1
IF (var >= 10) BREAK
LOOP
LOWER$ (string)
Returns the given string as all lowercase.
PRINT LOWER$(“Hello World”) REM prints “hello world”
LTRIM$ (string)
Returns the given string with all whitespace removed from only the left side.
var$ = LTRIM$(“ Hello World “) REM stores “Hello World “
MAX (number, number)
Returns the maximum value of the two given numbers.
a = RND() // generates a random number between 0 and 1
b = RND() // generates a random number between 0 and 1
c = MAX(a, b) REM stores the largest of the two into c
33
BASIC COMMANDS & FUNCTIONS
MID$ (string, number, number)
Returns a smaller section (substring) of a given string. The first parameter is the given string, the
second is the starting point from the left side, and the third optional parameter dictates how many
characters to return. If the third parameter is omitted, all remaining characters are returned.
Returns the minimum value of the two given numbers.
a = RND() // generates a random number between 0 and 1
b = RND() // generates a random number between 0 and 1
c = MIN(a, b) REM stores the smallest of the two in c
MINUTES
A parameter to the DATETIME function returning a two-digit number representation of the current
day, formatted as MM.
var = DATETIME(MINUTES) REM stores 39, inferring the 39th minute
MOD (number, number)
Returns the remainder of a division between the two given numbers. MOD performs floatingpoint
divisions and remainders. For integer-only divisions/remainders, use the % operator.
a = 102.5
b = 10
PRINT MOD(a, b) REM prints “2.5”, inferring a (102.5/10) calculation
PRINT a % b REM prints “2”, inferring a (102/10) calculation
MONTH
A parameter to the DATETIME function returning a two-digit number representation of the current
month, formatted as MM.
var = DATETIME(MONTH) REM stores 2, inferring February
NETMASK
Used in conjunction with the SETNETWORK command, NETMASK sets the given parameter as the
Netmask to use for IP Address on the network. The NETMASK command should be given after the
IP MANUAL entry and before an IP GATEWAY command.
SETNETWORK NETMASK, “192.168.0.1”
34
Basic Commands and Functions
NEXT
Declares the end of a FOR loop. The initial FOR variable may be optionally specified.
FOR a = 1 TO 10 STEP 2
PRINT “ “, a; REM prints “ 1 3 5 7 9”
NEXT a
NOT
Negates the expression immediately following. The ! operator may alternatively be used.
FOR a = 1 TO 10 STEP 2
IF (NOT a > 5) REM NOT effectively changes our expression to (a <= 5)
PRINT “ “, a; REM prints “ 1 3 5”
NEXT a
ON number GOSUB
Branches to one of a list of GOSUBs based on the given number/argument. For example, if the
given number is 1, the first GOSUB listed is used, if the number is 2, the second GOSUB, etc.
ON a GOSUB print1, print2, print3
NEXT a
END REM the final printout is: “ 1 (2) *3*”
LABEL print1
PRINT “ “, a;
RETURN
LABEL print2
PRINT “ (“, a;
PRINT “)”;
RETURN
LABEL print3
PRINT “ *”, a;
PRINT “*”;
RETURN
FOR a = 1 TO 3
ON number GOTO
Jumps to one of a list of GOTOs based on the given number/argument. For example, if the given
number is 1, the first GOTO listed is used, if the number is 2, the second GOTO, etc. Unlike GOSUB,
GOTO statements never return back to the point of the GOTO.
FOR a = 1 TO 3
ON a GOTO print1, print2, print3
NEXT a
END REM the final printout is: “ 1” as the other Labels are not reached
35
BASIC COMMANDS & FUNCTIONS
LABEL print3
PRINT “ *”, a;
PRINT “*”;
LABEL print2
PRINT “ (“, a;
PRINT “)”;
LABEL print1
PRINT “ “, a;
OPEN
Opens a file, serial (COM) port, network (Ethernet) port, or connects to a listening serial or
network port.
Files may be opened for either READING, WRITING, or APPENDING. A file opened with WRITING
mode will create a new le if the le doesn’t exist, or erase the contents of an existing le. To
prevent overwriting of an existing file, use the APPENDING option for write operations. Another
optional syntax may be used to determine if a file exists, as shown below in the file example.
Serial ports are opened with the following defaults: baud rate = 9600, data bits = 8, parity = none,
stop bits = 1, flow control = none, transmit char delay = 0, transmit line delay = 0. If other port
settings are desired, they must be specified prior to opening the port using the SETPORT
command, as shown below in the serial port example.
Ethernet ports are specified with either an IP address or hostname followed by a colon and port
number. To enable an Ethernet port to act as a Server (respond to incoming communication), a
port should be set up within the Listening Ports Setup using the touch screen interface.
Listening ports are configured within the Listening Ports Setup menus of the System 5000TM.
When communication occurs on a listening port, a Basic program can be initiated and retrieve/
respond to requests on that port. To enable that communication, the OPEN command should be
issued with “LISTENER” as its parameter. Subsequent PRINT and INPUT calls will then be directed to
and from the attached listening port. See the below example for further details. Note that ethernet
(e.g. TCP or UDP) and serial port configuration (e.g. baud rate) are configured within the Listening
Ports Setup menu. The “ETHERNET” parameter has been deprecated and is now synonymous with
“LISTENER”. Listening ports do not need to be closed using the CLOSE command.
All files and ports (except listening ports) will be automatically closed when a program ends.
File:
OPEN “SiteID.csv” FOR APPENDING AS #1
CLOSE #1
36
ENDIF
REM Check if le exists, if it doesn’t an OPEN #1 FOR READING will fail
Basic Commands and Functions
FileExists = 1
FileName$ = “LogFile.csv”
IF (NOT OPEN(#1, FileName$)) THEN
FileExists = 0
ELSE
CLOSE #1
ENDIF
Serial Port:
SETPORT 300, 8, none, 1, none, 50, 0 REM port settings
OPEN “COM 1” AS #5 REM open the COM at 300 baud w/50ms tx char delay
CLOSE #5
PRINT #2, headers$ REM Send our request for the web page
REM As the maximum receiving length is capped at 1024 characters,
REM multiple INPUT commands needs to be run to retrieve the content
INPUT #2 1000, webpage$ REM Give a full second for the first response
WHILE (LEN(webpage$) > 0)
PRINT webpage$ REM Print the contents to the terminal
INPUT #2 100, webpage$ REM Retrieve remaining contents(100ms waiting)
WEND
CLOSE #2
Listening Port:
REM Display a simple web page, probably via the Ethernet port
OPEN “LISTENER” AS #9
INPUT #9, rcv$
PRINT #9 “HTTP/1.0 200 OK”
PRINT #9 “”
PRINT #9 “<html>”
PRINT #9 “<head>”
PRINT #9 “<title>System 5000</title>”
PRINT #9 “</head>”
PRINT #9 “<body>”
GETTASK “myTask”, Task1Val$
GETTIMESTAMP “myTask”, Task1ts$
PRINT #9 “Task: “, Task1$, “ DateTime:”, Task1ts$, “ Value:”, Task1Val$
PRINT #9 “</body>”
PRINT #9 “</html>”
CLOSE #9
37
BASIC COMMANDS & FUNCTIONS
OR
A logical operator used between two expressions in conditional statements (e.g. if, while, etc).
Returns TRUE if either the left, right, or both expressions are TRUE, FALSE if both are FALSE.
var = 100
IF (var > 0 OR var < 50) PRINT “Small” REM prints “Small”
IF (var > 0 OR var < 150) PRINT “Large” REM prints “Large”
PI
A read-only constant containing the number 3.1415926535897932.
var = PI REM stores 3.14159 in var
PRINT
Writes characters to a file, serial/com port, network/ethernet connection or standard output. If
the PRINT statement is used without specifying an open file, serial port (#X), or ethernet
connection, the output is sent to the System 5000™ terminal. Generally, this will only be useful
while troubleshooting Basic programs. An automatic carriage return and line feed (\r\n) are
added to all PRINT statements unless the statement is ended with a semicolon (;). The USING
statement may also be appended for added precision or to set the number of digits to print
(specified with hashes “#”).
Serial communication:
PRINT “OPENING COM2” REM prints to terminal
OPEN “COM2” AS #4 REM “COM2” and “COM 2” are identical
REM Wake up the H-3531 sensor by sending a character
PRINT #4 “W” REM Wakes up our sensor
INPUT #4 6000, H3531$ REM retrieve our measurements (6 sec timeout)
PRINT H3531$ REM print our results to the terminal
CLOSE #4
File communication:
PRINT “OPENING SiteID.csv” REM prints to terminal
OPEN “SiteID.csv” FOR WRITING AS #1 REM WRITING mode creates a new file
PRINT #1 “Digital2,AC-In” REM newline automatically added
var = 1
var2 = 256.25
var3 = 12.565
REM following line prints “1,256.25”
PRINT #1 var, “,”, var2, “,”; REM newline not added
PRINT #1 var3 USING “##.##” REM prints “12.57” followed by a newline
38
PRINT #1 “Done” REM newline automatically added
CLOSE #1
Basic Commands and Functions
Network communication:
PRINT “OPENING Ethernet connection” REM prints to terminal
OPEN “192.168.0.1:20” AS #1 REM format must be host:port
PRINT #1 “Digital2,AC-In” REM newline automatically added
var = 1
var2 = 256.25
var3 = 12.565
REM following line prints “1,256.25”
PRINT #1 var, “,”, var2, “,”; REM newline not added
PRINT #1 var3 USING “##.##” REM prints “12.57” followed by a newline
PRINT #1 “Done” REM newline automatically added
CLOSE #1
QUADXX
Used in conjunction with the GETVALUE command, QUADXX requests a new Quadrature counter
measurement to be made on the specified Digital ports and stores the value in the given variable.
Used in conjunction with the SETVALUE command, DIFFXX specifies the Quadrature counter on
the specified ports to be set to the desired number. The counter will be set to the integer value of
the number if a floating point value is passed in.
GETVALUE DIFF34, var REM stores a new quadrature counter measurement of
REM ports 3-4 from the daughterboard in the var
REM variable
GETVALUE DIFF12 “SLOT2”, s$ REM stores a new quadrature counter
REM measurement of ports 1-2 from Slot 2 in
REM the s$ string variable
SETVALUE DIFF12, 12.5 REM sets the quadrature counter on ports 1-2 on
REM the daughterboard to 12 (INT(12.5))
a = 156.0
SETVALUE DIFF34 SLOT1, a+2 REM sets the quadrature counter on ports 3-4
REM on Slot 1 to 158 (a+2)
REM
Begins a comment extending to the end of the line. An apostrophe (“ ‘ ”) may alternatively be
used. REM does not need a statement separator if used on the same line as another statement.
REM This is a comment
‘ This is also a comment
PRINT “Hello World” REM This is a valid comment
PRINT “Hello World” ‘ This is also a valid comment
39
BASIC COMMANDS & FUNCTIONS
REPEAT
Begins a conditional loop encompassed by REPEAT and UNTIL. The condition is given after the
UNTIL statement and while evaluated as TRUE, will continue to iterate through the loop. Once the
UNTIL condition is evaluated as FALSE, the loop exits.
REPEAT
var = var + 1
PRINT “ “, var * var; REM prints “ 1 4 9 16 25”
UNTIL (var = 5)
RETURN
Returns control back to the calling line of a GOSUB call or a subroutine (SUB) call with an
optional value.
REM Calculate the Area of a Rectangle
heighth = 3
width = 4
Area = calc_area(heighth, width) REM stores 12 in Area
SUB calc_area(h, w)
A = h * w
RETURN A
END SUB
RIGHT$ (string, number)
Returns a string, starting from the right side, containing the given number of characters from the
given string.
var$ = “Analog Value: 12.5”
new_var$ = “A1:” + RIGHT$(var$, 4) REM stores “A1:12.5” in new_var$
RINSTR (string, string, number)
Returns the position, starting at 1, of the first occurrence of the second given string within the
rst given string beginning at the right. If the string is not found, zero is returned. The third
argument is an optional number, defaulting to the last element of the string, indicating the
starting position for the search. INSTR may be used to begin searching for a string from the left,
rather than the right.
var = RINSTR(“Analog 2: 3.5, Digital 4: 1”, “Digital”) REM stores 16
var = RINSTR(“Analog 1: 1.25, Analog 2: 2.5”, “Analog”, 5) REM stores 1
RND (number)
Returns a random number. An optional number may be specified for the maximum range (from
zero to, but not including, the given number). If no number is given, the default is 1.
40
x = RND() REM stores a random number between 0-0.99999 in x
y = RND(5) REM stores a random number between 0-4.99999 in y
Basic Commands and Functions
RTRIM$ (string)
Returns the given string with all whitespace removed from only the right side.
PRINT RTRIM$(“ Hello World “) REM prints “ Hello World”
SCANRATE
Used in conjunction with the GETDB command, SCANRATE requests the given Task’s scan
rate and stores it in the given variable. The scan rate is given in seconds.
Used in conjunction with the SETDB command, SCANRATE sets the given Task’s scan rate to
the given value. The scan rate should be specified in seconds.
GETDB SCANRATE “myTask”, var REM stores the scan rate of Task “myTask”
REM in the var$ variable
SETDB SCANRATE “myTask”, 120 REM sets the scan rate of “myTask”
REM to 2 minutes (120 seconds)
SECONDS
A parameter to the DATETIME function returning a two-digit number representation of the current
seconds, formatted as SS.
var = DATETIME(SECONDS) REM stores 59, inferring the 59th second
SEEK
Sets the position from which the next INPUT statement will read from within an open file. The
first parameter is the open file, the second parameter tells where to set the next read position, and
the third is an optional setting of either “BEGINNING”, “CURRENT”, or “END”. “BEGINNING” sets the
count from the beginning of the file (and is the default if not specified), “CURRENT” counts from
the current read position from within the file, and “END” counts from the end of the file. The TELL
command retrieves the current read position of the given file.
myTask Analog2 WindSpeed
56.23 2.25 126.5
OPEN “SiteID.csv” FOR READING AS #1
SEEK #1, LEN(“myTask”) REM sets our position to Analog2
INPUT #1 “\t”, var$
SEEK #1, -11, “END” REM sets our position to the Analog2 measurement
INPUT #1 “\t”, var2$
PRINT var$, “ is “, var2$ REM prints “Analog2 is 2.25”
CLOSE #1
41
BASIC COMMANDS & FUNCTIONS
SETDB
Sets the requested database value to the given number or string. Available parameters are SITEID
and SCANRATE with a mentioned Task and number value (measured in seconds).
SETDB SITEID, “Site101”
task$ = “myTask”
SETDB SCANRATE task$, 60 REM Sets the Scan Rate for myTask to 1 min.
SETNETWORK
Sets network settings to the given number or string. Available parameters are IP, NETMASK,
GATEWAY, and DNS. IP and DNS also require either an AUTO or MANUAL parameter. IP AUTO will
automatically set the Netmask and Gateway as well as DNS settings. Note that to use a Manual DNS
entry, the IP settings must also be set to Manual. If multiple DNS MANUAL entries are specified, the
most recent two will be saved with the latter set as the Preferred DNS.
SETNETWORK IP AUTO
SETNETWORK IP MANUAL, “192.168.0.82”
SETNETWORK NETMASK, “255.255.255.0”
SETNETWORK GATEWAY, “192.168.0.246”
SETNETWORK DNS AUTO
SETNETWORK DNS MANUAL, “192.168.0.6” REM set as Alternate DNS
SETNETWORK DNS MANUAL, “192.168.0.5” REM set as Preferred DNS
SETPORT
Sets the serial port settings for unopened communication ports. Serial ports are opened with the
following defaults: baud rate = 9600, data bits = 8, parity = none, stop bits = 1, flow control = none,
transmit char delay = 0, transmit line delay = 0. If other port settings are desired, they must be
specified prior to opening the port. Parity can be set to None, Even, or Odd. Flow Control can be
set to None, Software, Hardware, or Both. Port settings only need to be set once and will affect all
future port openings.
SETPORT 300, 8, none, 1, none, 50, 0 REM port settings
OPEN “COM 1” AS #5 REM open the COM at 300 baud w/50ms tx char delay
CLOSE #5
SETPOWER
Sets the power to the given piece of hardware. Available parameters are ACTIVELED (Active LED),
ETHERNET (10/100 BaseT), SW12V (Switched +12V), and the 5VREF (+5V Reference) that can be
turned On or Off by specifying any number greater than zero to turn it On or any number less than
or equal to zero to turn it Off. An optional SLOTX may be specied for option cards (if not, the
daughterboard is presumed), followed by the requested value.
SETPOWER ACTIVELED, 1 REM Sets the Active LED to On
SETPOWER ETHERNET, 0 REM Sets the Ethernet port to Off
SETPOWER SW12V, 1 REM Sets the Switched +12V to On
42
SETPOWER 5VREF SLOT1, 1 REM Sets the +5V Ref (Slot 1) to On
Basic Commands and Functions
SETTASK
Sets the provided Task’s most recent value to the given number or string. If an unknown Task is
specified, no value will be stored.
GETTASK task$, a
SETTASK “myTask”, a * 2 REM doubles the last measurement value of myTask
task$ = “myTask”
SETTIMESTAMP
Sets the provided Task’s most recent timestamp to the given number or string. If an unknown Task
is specified, no value will be stored.
REM Find the Maximum value within the last four entries and set our
REM most recent entry to that datetimestamp and maximum value
Task$ = “myTask”
TaskMax = 0
TaskMaxDate$ = “”
FOR i = 1 TO 4
‘ get our time and date
GETTIMESTAMP Task$ i, Timestamp$
GETTASK Task$ i, TaskValue$
‘ Compare our Max values
TaskValue = VAL(TaskValue$)
IF (TaskMax == 0 OR TaskValue > TaskMax) THEN
TaskMax = TaskValue
TaskMaxDate$ = Timestamp$
ENDIF
NEXT i
Used to change current hardware settings. Available parameters are DIGITALX (Digital Port Level),
COUNTERX (Event Counter), QUADXX (Quadrature Counter), and 420MA (4-20mA Output) where
X is a number indicating the requested port. An optional SLOTX may be specified for option cards
(if not, the daughterboard is presumed), followed by the requested value. Note also that Counter
values should be integer (non-decimal) values.
a = 16.0
SETVALUE DIGITAL1 SLOT3, a REM sets Digital port 1 on Slot 3 high
SGN (number)
Returns an integer (-1, 0, or 1) indicating the sign (negative, zero, or positive respectively) of the
given number.
var = SGN(-32.645) REM stores -1
var = SGN(1023.98) REM stores 1
43
BASIC COMMANDS & FUNCTIONS
SIN ( )
Returns the sine value of the given number.
var = SIN(PI/2) REM stores 1 in the var variable
PRINT SIN(0) REM prints “0”
SITEID
Used in conjunction with the GETDB command, SITEID requests the System 5000™’s Site ID
as specified in the System Settings screen and stores it in the given string variable.
Used in conjunction with the SETDB command, SITEID sets the System 5000™’s Site ID to the
given value.
GETDB SITEID, var$ REM stores the current Site ID in the var$ variable
SETDB SITEID, “Site_120” REM sets the Site ID to “Site_120”
SLEEP
Causes the program to pause execution for the specified number of seconds. A decimal number
may be used to specify more specific and smaller time increments (e.g. milliseconds). SLEEP
and DELAY are identical commands.
DELAY 0.25 REM pauses the program for 0.25 seconds
SLEEP 2.5 REM pauses the program for 2.5 seconds
SLOTX
An optional parameter in SETVALUE and GETVALUE commands to specify the use of an option
card. If not specified, SLOT0 is presumed (the daughterboard). May also be substituted with the
string representation of “SLOTX”.
GETVALUE ANALOG3 SLOT2, s$ REM stores a new Analog Channel 3 measurement
REM from Slot 2 in the s$ string variable
SETVALUE COUNTER1 “SLOT3”, 25 REM sets the Counter on Digital Port 1 on
REM Slot 3 to 25
SPLIT (string, array, string)
Splits apart a string into an array of strings. The first parameter provides the string to split apart.
The second parameter provides the array which the new substrings will fill. The optional third
parameter provides the delimiters or characters that determine where to split the primary string.
If more than one delimiter is specified, splitting will occur at each character given (e.g. if a
comma and hyphen are given “,-”, content will be split on any commas or hyphens found as in
the example below). If no delimiter is specified, whitespace will be used as the delimiter (e.g.
spaces and tabs).
Empty elements in the array are created if two delimiters are next to each other (see element 5
44
below, regarding the sequence “Analog2,-Analog4”). The TOKEN function, on the other
hand, does not add empty elements if two or more delimiters are in sequence.
Basic Commands and Functions
The array will be automatically sized (larger or smaller) based on the number of strings that are
produced by the split. The number of strings produced will also be returned by the function.
var$ = “Analog1,Analog2,Analog3-Analog2,-Analog4”
ARRAY arr$(1)
result = SPLIT(var$, arr$(), “,-”) REM split on commas or dashes
FOR i = 1 TO result REM result = 6
REM prints “1:Analog1 2:Analog2 3:Analog3 4:Analog2 5: 6:Analog4”
PRINT i, “:”, arr$(i), “ “;
NEXT i
SQR (number)
Returns the squared value of the given number. The caret (“^”) may also be used to raise a number
to a power, such as 2.
var = SQR(5) REM stores 25 in the var variable
PRINT 4^2 REM prints “16”
SQRT (number)
Returns the square root value of the given number. The caret (“^”) may also be used to raise a
number to a power, such as 1/2.
var = SQRT(25) REM stores 5 in the var variable
PRINT 16^(1/2) REM prints “4”
STEP
Specifies an optional increment in a FOR loop. Positive or negative numbers may be used.
FOR a = 10 TO 1 STEP -2
PRINT “ “, a; REM prints “ 10 8 6 4 2”
NEXT a
STR$ (number, string)
Returns a string for the given number. An optional second parameter string may be specified to
declare the format to be used. Formats are specified using the hash character (“#”). If not enough
hashes are specified, the format will be returned.
var$ = STR$(18.265, “##.####”) REM stores “18.2650” in var$
var$ = STR$(18.265, “#######”) REM stores “ 18”
PRINT STR$(18.265) REM prints “18.265”
PRINT STR$(18.265, “#.#####”) REM prints “#.#####”
45
BASIC COMMANDS & FUNCTIONS
SUB
Declares a user-defined subroutine. Subroutines can specify and accept multiple arguments and
can return a number or string value using the RETURN statement. The END SUB statement
marks the end of a subroutine. For consistency, it is recommended that any subroutine returning
a string should have the subroutine’s name end with a dollar-sign (“$”).
Specific SUB commands may also be used as special entry points for designated IO. These SUB
commands are case-sensitive and only called if two conditions are met: 1) The special SUB
command is declared properly, and 2) the designated IO or Network option calls the program.
This allows only desired segments of code to be run based on the calling process. For instance, if
a single program contained both the SUB Input() and SUB Network() routines, only the Input
subroutine would be run when the program is called from a Task Input, and only the Network
subroutine would be called when a connection is made on a Listening Port. If an Output from a
Task called the program, the program would run the program, like normal, from the beginning
(as no entry point/SUB Output() command was found). Once the subroutine ends, the basic
program is ended as well and no other portions of the code would be run. The case-sensitive
subroutines of SUB Input(), SUB Output(), SUB Serial(), and SUB Network() are available for
use, though not required for standard program execution.
REM Calculate the Volume of a Rectangle
heighth = 3
width = 4
depth = 5
volume = calc_volume(heighth, width, depth)
PRINT “Volume: “, volume REM prints “Volume: 60”
SUB calc_volume(h, w, d)
vol = h * w * d
RETURN vol
END SUB
SUB Output()
REM This subroutine only will run if called from a Task Output
PRINT heighth REM prints 0 as heighth was not declared in this routine
END SUB
SW12V
Used in conjunction with the GETPOWER command, SW12V requests the current state of the
Switched +12 Volt and stores the value in the given variable. A 1 is stored if On, 0 if Off.
Used in conjunction with the SETPOWER command, SW12V specifies the Switched +12 Volt
to be turned on or off. Numbers greater than zero will turn the Switched +12 Volt On, and
46
Basic Commands and Functions
numbers less than or equal to zero will turn the Switched +12 Volt Off.
GETPOWER SW12V, var REM stores a 1 if On, 0 if Off for the Switched +12V
REM on the daughterboard in the var variable
SETPOWER SW12V, 0 REM turns the Switched +12 Volt Off
a = 16.0
SETPOWER SW12V, a REM turns the Switched +12 Volt On
SWITCH
Declares the beginning of a SWITCH-CASE clause. The single variable given after the SWITCH
keyword specifies the character or characters to match. Once a CASE match is made, the program
will continue until a BREAK statement is seen, at which point the program will continue execution
at the END SWITCH statement. A DEFAULT route may be specified and followed if no other CASE
statements cause a match to occur.
var = 6
SWITCH var
CASE 0:
CASE 1:
PRINT “Number too low”
BREAK
CASE 2: PRINT “Low” : BREAK
CASE 4: PRINT “Mid” : BREAK
CASE 6:
PRINT “High” REM prints “High”
BREAK
DEFAULT: PRINT “Unknown number: “, var
END SWITCH
TAN (number)
Returns the tangent value of the given number.
var = TAN(PI/4) REM stores 1 in the var variable
PRINT TAN(0) REM prints “0”
TASKNAME
Used in conjunction with the GETDB command, TASKNAME requests calling Task’s name. For
example, if a Task is created with the name of “myTask”, GETDB TASKNAME will store the value of
“myTask” into the given string variable.
GETDB TASKNAME, var$ REM stores the calling Task’s name in var$
47
BASIC COMMANDS & FUNCTIONS
TELL (filenumber)
Returns the current read position of the given file number.
Presuming SiteID.csv contains:
Digital2,AC-In
1,256.25
OPEN “SiteID.csv” FOR READING AS #1
INPUT #1, var$
PRINT var$ REM prints “Digital2,AC-In”
PRINT TELL(#1) REM prints “15”
SEEK #1, -6, “CURRENT”
PRINT TELL(#1) REM prints “9”
INPUT #1, var$
PRINT var$ REM prints “AC-In”
CLOSE #1
TEMP
Used in conjunction with the GETVALUE command, TEMP requests a new measurement to be
made of the internal temperature and stores the value in the given variable.
GETVALUE TEMP, var REM stores a new measurement of the internal
REM temperature in the var variable
THEN
Used with the IF statement to specify a multi-line IF-THEN clause.
var = 250
IF (var >= 500) THEN
PRINT “Very Large number”
ELSEIF (var >= 250) THEN
PRINT “Large number” REM prints “Large number”
ELSE
PRINT “Small number”
ENDIF
TIME
A parameter to the DATETIME function returning a six-digit number representation of the current
time, formatted as HHMMSS.
var = DATETIME(TIME) REM stores 53237, inferring 05:32:37
48
Basic Commands and Functions
TIME$
A parameter to the DATETIME function returning a string representation of the current time,
formatted as “HH:MM:SS”.
var$ = DATETIME(TIME$) REM stores “05:32:37”
TO
Used with the FOR statement to specify the range of the loop.
FOR a = 1 TO 10
PRINT “ “, a; REM prints “ 1 2 3 4 5 6 7 8 9 10”
NEXT a
TOKEN (string, array, string)
Splits apart a string into an array of strings. The first parameter provides the string to split apart.
The second parameter provides the array which the new substrings will fill. The optional third
parameter provides the delimiters or characters that determine where to split the primary string.
If more than one delimiter is specified, splitting will occur at each character given (e.g. if a comma
and hyphen are given “,-”, content will be split on any commas or hyphens found as in the example
below). If no delimiter is specified, whitespace will be used as the delimiter (e.g. spaces and tabs).
Empty elements in the array are not created if two delimiters are next to each other (see element
5 below, regarding the sequence “Analog2,-Analog4”). The SPLIT function, on the other hand,
does add empty elements if two or more delimiters are in sequence.
The array will be automatically sized (larger or smaller) based on the number of strings that are
produced by the split. The number of strings produced will also be returned by the function.
var$ = “Analog1,Analog2,Analog3-Analog2,-Analog4”
ARRAY arr$(1)
result = TOKEN(var$, arr$(), “,-”) REM splitting on commas and dashes
FOR i = 1 TO result REM result = 5
REM prints “1:Analog1 2:Analog2 3:Analog3 4:Analog2 5:Analog4”
PRINT i, “:”, arr$(i), “ “;
NEXT i
TRIM$ (string)
Returns the given string with all whitespace removed from both the left and right side.
PRINT TRIM$(“ Hello World “) REM prints “Hello World”
TRUE
A read-only constant containing the number 1.
var = 1
IF (var = TRUE) PRINT “passed” REM prints “passed”
49
BASIC COMMANDS & FUNCTIONS
UNTIL
Marks the end of a conditional loop encompassed by REPEAT and UNTIL. The condition is given
after the UNTIL statement and while evaluated as TRUE, will continue to iterate through the loop.
Once the UNTIL condition is evaluated as FALSE, the loop exits.
REPEAT
var = var + 1
PRINT “ “, var * var; REM prints “ 1 4 9 16 25”
UNTIL (var = 5)
UPPER$ (string)
Returns the given string as all uppercase.
PRINT UPPER$(“Hello World”) REM prints “HELLO WORLD”
USING
Used with the PRINT statement to specify the format of the given number. Format is specified
using hashes (“#”). If more hashes are provided than needed, the beginning is space filled, the
end zero-padded. If not enough hashes are given before the decimal, the hash format is returned.
PRINT 26.25345 USING “##.###” REM prints “26.253”
var = 1028.265
PRINT var USING “####.####” REM prints “1028.2650”
PRINT var USING “#######” REM prints “ 1028”
PRINT var USING “##.##” REM prints “##.##”
VAL (string)
Returns a number for the given string.
var = VAL(“26.250”)
PRINT var REM prints “26.25”
PRINT VAL(“ 22”) REM prints “22”
PRINT VAL(“a 22”) REM prints “0”
var$ = “128.5”
PRINT VAL(var$) REM prints “128.5”
WEND
Marks the end of a conditional WHILE-WEND loop. END WHILE may also be used instead of
WEND.
PRINT “ “, var;
var = var + 1.5
50
WEND REM prints “ 0 1.5 3 4.5 6 7.5 9”
WHILE (var < 10)
Basic Commands and Functions
WHILE
Marks the beginning of a conditional WHILE-WEND loop. The condition is specified after the
WHILE keyword. As long as the condition evaluates to TRUE, the loop will continue to iterate.
Once the condition evaluates to FALSE, the loop will exit.
Presuming SiteID.csv contains:
Digital2,AC-In
1,256.25
OPEN “SiteID.csv” FOR READING AS #1
WHILE (!EOF(#1))
INPUT #1 “,”, var$
PRINT var$, “ “; REM prints “Digital2 AC-In 1 256.25 “
WEND
CLOSE #1
XOR (number, number)
Returns the bitwise exclusive or (as a number) of the two numeric arguments.
var = XOR(6, 2)
PRINT “XOR: “, var REM prints “XOR: 4”
YEAR
A parameter to the DATETIME function returning a two-digit number representation of the current
year, formatted as YY.
var = DATETIME(YEAR) REM stores 9, inferring 2009
51
Xylem
1) The tissue in plants that brings water upward from the roots;
2) a leading global water technology company.
We’re 12,000 people unied in a common purpose: creating innovative solutions
to meet our world’s water needs. Developing new technologies that will improve
the way water is used, conserved, and re-used in the future is central to our work.
We move, treat, analyze, and return water to the environment, and we help people
use water efficiently, in their homes, buildings, factories and farms. In more than
150 countries, we have strong, long-standing relationships with customers who
know us for our powerful combination of leading product brands and applications
expertise, backed by a legacy of innovation.
For more information on how Xylem can help you, go to www.xyleminc.com
Xylem—WaterLOG
95 W 100 S, Suite 150
Logan, UT 84321
Tel +1.435.753.2212
Fax +1.435.753.7669
www.waterlog.com