Xylem System 5000 User Manual

BASIC PROGRAMMING MANUAL
V1.4.4
System H-5000™
D32 0414
CONTENTS
Introduction to Basic Programming.....................................2
Basic Features.....................................................................
Basic Fundamentals............................................................
Program Execution.......................................................
Error Handling...................................................................
Grammar............................................................................
Comments...........................................................................
Variables, Strings and Arrays............................................
Control Statements and Loops........................................
Operators..........................................................................
Math Functions...................................................................
Subroutines........................................................................
File I/O
Serial and Network I/O.....................................................
Escape Sequences and Hex Values................................. 7
String Processing...............................................................
System 5000™ Integration............................................... 8
Installing Basic Programs.................................................. 8
Advanced Programming with Symbols..........................
Commands and Functions...................................................11
420MA................................................................................
5VREF..................................................................................
ABS (number)....................................................................
ACIN
ACOS (number).................................................................
ACTIVELED ALARM$ ANALOGX
AND.....................................................................................
ARRAY.................................................................................
ARRAYDIM (array)..............................................................
ARRAYSIZE (array, number)..............................................
ASC (string).......................................................................
ASIN (number)..................................................................
ATAN (number).................................................................
BATT
BREAK..............................................................................
CASE...................................................................................
CEIL (number)..................................................................
CHECKRETURN
CHR$ (number)................................................................
CLEARSDI ( )....................................................................
CLOSE...............................................................................
CONTINUE....................................................................
COS (number)..................................................................
COUNTERX DATE DATE$
DATETIME.......................................................................
DAY
DEFAULT...........................................................................
DELAY..............................................................................
12 12 13 13 13 13 14 14 14 14 15 15 15 15 16 16 16 16 16 17 17 17 17 18 18 18 18 19 19 19 19 20
DIFFXX.............................................................................
3 3 4 4 4 5 5 6 6 6 6 7 7
8
9
DIGITALX..........................................................................
DNS...................................................................................
DO.....................................................................................
ELSE...................................................................................
END....................................................................................
ENDIF.................................................................................
END SUB...........................................................................
EOF ( )................................................................................
EPOCH..............................................................................
EPOCHDAY.......................................................................
ERROR...............................................................................
ERRORSTR........................................................................
ETHERNET........................................................................
EULER................................................................................
EXP ( )................................................................................
FALSE................................................................................
FLOOR ( )..........................................................................
FLUSH...............................................................................
FOR...................................................................................
FRAC ( ).............................................................................
FREQUENCYX.................................................................
GATEWAY........................................................................
GETDB..............................................................................
GETPOWER.....................................................................
GETSDI.............................................................................
GETTASK..........................................................................
GETTIMESTAMP...............................................................
GETVALUE........................................................................
GLOBAL............................................................................
GOSUB.............................................................................
GOTO................................................................................
H377C ( )..........................................................................
H377F ( )...........................................................................
HEX$( )..............................................................................
HOURS.............................................................................
IF........................................................................................
INPUT................................................................................
INSTR ( )............................................................................
INT ( )................................................................................
IP.......................................................................................
JDAY.................................................................................
LABEL..............................................................................
LEFT$ ( )...........................................................................
LEN ( )...............................................................................
LINE INPUT.......................................................................
LISTENER.........................................................................
LN ( )................................................................................
LOCAL.............................................................................
LOG ( ).............................................................................
LOOP...............................................................................
20 20 21 21 21 21 22 22 22 22 23 23 23 23 23 24 24 24 24 24 25 25 25 25 25 26 26 27 27 27 28 28 29 29 29 29 29 30 30 31 31 31 31 31 32 32 32 32 32 33 33 33
Contents
LOWER$ ( ).......................................................................
LTRIM$ ( )..........................................................................
MAX ( )..............................................................................
MID$ ( ).............................................................................
MIN ( )................................................................................
MINUTES..........................................................................
MOD ( ).............................................................................
MONTH............................................................................
NETMASK.........................................................................
NEXT..................................................................................
NOT...................................................................................
ON GOSUB......................................................................
ON GOTO........................................................................
OPEN.................................................................................
OR......................................................................................
PI........................................................................................
PRINT.................................................................................
QUADXX...........................................................................
REM...................................................................................
REPEAT..............................................................................
RETURN.............................................................................
RIGHT$ ( )..........................................................................
RINSTR ( )...........................................................................
RND ( )...............................................................................
RTRIM$ ( )..........................................................................
SCANRATE........................................................................
SECONDS.........................................................................
SEEK..................................................................................
SETDB...............................................................................
SETNETWORK.................................................................
SETPORT...........................................................................
SETPOWER.......................................................................
SETTASK............................................................................
SETTIMESTAMP................................................................
SETVALUE.........................................................................
SGN ( )..............................................................................
SIN ( )..................................................................................
SITEID................................................................................
SLEEP..................................................................................
SLOTX...............................................................................
SPLIT ( ).............................................................................
SQR ( )...............................................................................
SQRT ( )...........................................................................
STEP...................................................................................
STR$ ( )..............................................................................
SUB....................................................................................
SW12V..............................................................................
SWITCH..............................................................................
TAN ( )...............................................................................
TASKNAME.......................................................................
TELL ( )..............................................................................
TEMP..................................................................................
33 33 33 34 34 34 34 34 34 35 35 35 35 36 37 37 37 39 39 40 40 40 40 40 41 41 41 41 42 42 42 42 43 43 43 43 44 44 44 44 45 45 45 45 46 46 47 47 47 48 48 48
THEN.................................................................................
TIME.................................................................................
TIME$...............................................................................
TO.......................................................................................
TOKEN ( ).........................................................................
TRIM$ ( )...........................................................................
TRUE...................................................................................
UNTIL.................................................................................
UPPER$ ( )........................................................................
USING...............................................................................
VAL ( )...............................................................................
WEND...............................................................................
WHILE...............................................................................
XOR..................................................................................
YEAR................................................................................
48 48 49 49 49 49 49 50 50 50 50 50 51 51 51
1
BASIC FEATURES &
01 /
FUNDAMENTALS
2
Basic Features and Fundamentals
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 specied 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. Non­printable 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
\b 8 08 backspace
\t 9 09 horizontal tab
\n 10 0A newline
\v 11 0B vertical tab
\f 12 0C form feed \r 13 0D carriage return
\” 34 22 double quote
\’ 39 27 single quote
\\ 92 5C backslash
\xXX N/A N/A hex value
ASCII Value Hex Value Description
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 specied 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 modied 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 species the array and number species
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
Loading...
+ 37 hidden pages