Xylem XL-BASIC User Manual

Chapter 23
XL-BASIC Programming Guide
Version Changes (available on version 2.07 of the XL series data logger)
!Changes to the ‘input’ command to not change the variable value if no input was received !Added ‘printsdi’ command, print to the SDI-12 port without any retries. !Added ‘p12vxon’ command, turn on the 12 volt excite, (Only available on newer
hardware).
hardware).
!Added ‘settimeout (x)’ command, set the system time out value from 15 to 600 seconds. !Added ‘opencom2’, ‘print2’ and ‘closecom2’ commands, allows printing to com port
two.
!Added ‘logvalx’ variable, an indirect variable normally based on a log column function. !Added ‘reset’ variable, returns the number of times the system has reset. !Described the ‘basicx’ variable.
Version Changes (available on version 2.10 of the XL series data logger)
!Added input commands for com port 2 and 3 !Added fluchcom1, flushcom2, and flushcom3 commands. !Updated This document.
XL-BASIC Programs:
The XL™ series data loggers have a built in BASIC interpreter for handling specialized operations outside the normal use of the data logger. Since this BASIC interpreter is specific to the XL™ series of data loggers it is called XL-BASIC. XL-BASIC handles many of the standard BASIC commands, but also provides access to the I/O and other features of the XL™ series data logger.
Basic1 to Basic5 There are five basic programs that can be called any time the system is collecting data to log or to send to the GOES radio, etc. To execute one of the five programs, select it from the source list just as “Stage” or “Ana1" is selected. Each XL-BASIC program has a defined variable that will be used as a return value for the function that caused the XL-BASIC program to execute. For example, as the system processes the data to log, it looks at the source for each column. The first column is normally set to “Date” so the current date is placed in column 1. Column 2 is normally time and a time stamp is placed in this column. If column 3 source was set to “Basic1", then the BASIC 1 program would execute and the value in variable “Basic1" would be placed in the third column.
A BASIC program is written using a standard text editor on a PC and then loaded into the XL series data logger. Each BASIC program must be 8K bytes or less in size. The size of the
XL™ SERIES XL-BASIC Programming Guide 23-1
program includes all commands, comments, remarks, and spacing. If the size of the file becomes too big then cut down on the remarks or the spacing, or break the tasks into two separate programs.
Variables:
Since the system is limited on RAM, and to keep the operation of the BASIC programming simple, only predefined variables will be used. All variables types will be double precision floating point variables. All standard system variables will be accessible to the XL-BASIC interpreter plus some generic variables used only by the XL-BASIC interpreter system. In the program the variables may be upper or lower case, here they are shown in lower case.
Main BASIC Program Variables:
Variable Name
basic1 basic2 basic3 basic4 basic5
The basicx Variable:
This is not a separate variable but is actually an indirect link to one of the normal basic variables, 1 to 5. A program can return a value using the variable associated to the location number where the basic program is loaded. For example a program loaded into basic program location 1 must use the variable basic1 as the return variable. Now a program can use the name basicx as the return variable which allows the program to be loaded in any program location. If loaded into program location three, then when the program updates the basicx variable it is actually updating the variable basic3.
General Purpose Variables:
Type Description
Read / Write These variables are used to return values from Basic program 1
to 5 to the menu option calling the BASIC program. These variables are initialized to 0.0 when scanning is enabled, and will retain any modifications between scans. On return the value will depend on the users BASIC program.
Variable Name
a to z Read / Write 26 General purpose variables initialized to 0.0 when scanning is
23-2 XL-BASIC Programming Guide XL™ SERIES
Type Description
enabled. Any value changes will be retained between program execution and between scans
Standard Input Variables:
Variable Type Description
Stage Read / Write The last measured stage value is returned. (Only available on the
H-350XL and the H-510XL) RemStage Read / Write The last measured value for the remote stage variable is returned. LastStage Read / Write The stage value measured on the previous scan will be returned. Only
available on the H-350). PtTemp Read / Write The last measured PtTemp value is returned. (Only on the H-350XL) PSI Read / Write The last measured PSI value is returned. (Only on the H-350XL) AnaX Read / Write The last measured value for analog channel X (X = 1 to 4) is returned. Freq Read / Write The last measured freq value is returned. Digio1 Read / Write The last measured input state for digital channel 1 is returned. Digio2 Read / Write The last measured input state for digital channel 2 is returned. Counts Read / Write The last measured count value is returned. Totcnt Read / Write The last measured total count value is returned. Countrate Read / Write The current count rate on the counter input. Encodr Read / Write The last measured encoder input value is returned. Tscans Read / Write The total scans value is returned. SdiAP Read / Write The last measured value for the selected SDI-12 variable is returned
A = address 0 to 9, P = parameter 1 to 9 FntXX Read / Write The last calculated value for function XX is returned. (XX = 01 to 40) BasicX Read / Write The value of one program can be used in other programs. (X = 1 to 5)
Note: Standard input variables are normally read only but may also be assigned a new value
directly in the XL-BASIC program regardless of the variables corresponding hardware input condition. Be aware that based on system configuration the input variable could be updated by the system after the variable was set by the XL BASIC program. Writing to these variables should be avoided or only used in advanced applications. For example, in the following segment of code, the second line makes the first line useless.
measure(ana1) measurement analog input 1 now and update its variable. ana1 = 12.34 Sets variable ana1 to 12.34 regardless of the voltage on analog 1.
XL™ SERIES XL-BASIC Programming Guide 23-3
Read Only Variables:
Variable Type Description
Date Read Only The date is returned in the format YYMMDD.0000 Time Read Only The time is returned in the format HHMMSS.0000 seconds Read Only Return the current seconds in the format SS.0000 minutes Read Only Return the current minutes in the format MM.0000 hours Read Only Return the current hours in the format HH.0000 day Read Only Return the current day in the format DD.0000 month Read Only Return the current month in the format MM.0000 year Read Only Return the current year in the format YY.0000 Batt Read Only The current battery voltage reading is returned minbatt Read Only Return the minimum battery voltage measured since option was reset. maxbatt Read Only Return the maximum battery voltage measured since option was reset. tankpsi Read Only Return H-355 tank PSI if an H-355 is connected. linepsi Read Only Return H-355 line PSI if an H-355 is connected. purgepsi Read Only Returns H-355 p urge PSI setti ng. purgedur Read Only Returns H-355 p urge duration setting. bubrate Read Only Returns H-355 bub ble rate setting. Purge Read Only Returns H-355 purge status, 0 = bubbler communication error.
1 = request for purge accepted.
2 = alrea dy p urging. Resets Read Only Returns the number of times the system has reset. LogvalX Read Only Returns the value associated to a log column when the column is setup to
perform some function on the data like calculating the average, etc. The ‘X’ is the log column 01 to 25.
Note: The read only variables may be read but should not be written. Trying to set or write one
of these variables to some value will have no affect, and the program will continue on under normal operation. If one of these variables is set to some value and then read again, the value returned will not be the value set by the program but will be a value based on the function behind the variable.
23-4 XL-BASIC Programming Guide XL™ SERIES
Math Functions:
Basic Math Operations
+, -, *, /. Standard Math operators
% Modulo divide, returns the remainder from the standard division ^ Power operation, X^Y is X raised to the power of Y, for example 2^8 = 256
Trigonometry Operations (Degrees)
sin(x) cos(x) tan(x) asin(x) acos(x) atan( x)
Trigonometry Operations (Radians)
sinr(x) cosr(x) tanr(x) asinr(x) a cosr(x) atanr(x)
Logarithmic Operations
log(x) ln(x)
Misc Function Operations
abs(x) Absolute value of x.
int(x) Integer portion of x.
sqrt(x) Square root of x.
int(x) Integer portion of x.
h377f(anaX) Convert voltage on analog channel X to a temperature in degrees (f) based
on math equation for a model H-377 temperature probe.
h377c(anaX) Convert voltage on analog channel X to a temperature in degrees (c) based
on math equation for a model H-377 temperature probe.
XL™ SERIES XL-BASIC Programming Guide 23-5
XL-BASIC Command Summary:
PROGRAM FLOW / CONTROL COMMANDS COMMAND DESCRIPTION
REM Add remarks to the program for documentation. DELAY(xxxx) Delay or wait for xxxx milliseconds, 1 to 65000. GOSUB xxxx Go to a subroutine at line number ‘xxxx’. RETURN Return from the subroutine. GOTO xxxx Go to line number ‘xxxx’. FOR / TO / NEXT Loop commands IF / THEN Conditional program execution END End marker for all programs.
SENSOR INPUT COMMANDS
MEASURE(xxxxx) Take a new measurement from the selected input. VXON Turn on the 5.0 volt excitation. VXOFF Turn off the 5.0 volt excitation. P12VXON Turn on the 12 volt excitation. (Hardware Rev N and newer only) P12VXOFF Turn off the 12 volt excitation. (Hardware Rev N and newer only) SETDIG1 Set digital I/O 1 high. SETDIG2 Set digital I/O 2 high. CLEARDIG1 Clear digital I/O 1 to a low state. CLEARDIG2 Clear digital I/O 2 to a low state. CURRENTLOOP(a) Set the 4 to 20 mA current output level to ‘a’.
23-6 XL-BASIC Programming Guide XL™ SERIES
COM PORT COMMANDS
OPENCOMx Open RS-232 Com Port x for Input and Print operations. (x = 1 to 3) CLOSECOMx Turn off com port x (x = 1 to 3) FLUSHCOMx Clear out the input buffer for Com Port x (x = 1 to 3) PRINT Send text and data to com port 1. PRINT2 Send text and data to com port 2 PRINT3 Send text and data to com port 3 PRINT4 Send text and data to com port 4, this is the RS485 port and it will
turn on automatically as needed. This port has no input options. INPUT Get numeric values from com port 1. INPUT2 Get numeric values from com port 2. INPUT3 Get numeric values from com port 3. INPUTDELAY(x) Set how long to wait for input on the serial ports, or keypad. DIGITS(x) Set the number of digits to the right of the decimal point to display.
BUILT IN DISPLAY / KEYPAD COMMANDS
DISPLAY Send text and data to the local display DISPCLEAR Clear the local display. DISPCURSER(x) Set the curser position for the local display to ‘x’. DISPOFF Turn off the local display. INKEY Get a key press input from the local display. LEDON Turn on the Error LED. LEDOFF Turn off the Error LED.
XL™ SERIES XL-BASIC Programming Guide 23-7
Loading...
+ 14 hidden pages