Basic commands & functions – Xylem System 5000 BASIC Manual User Manual

Page 48

Advertising
background image

46

BASIC COMMANDS & FUNCTIONS

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

SUB

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

SW12V

Advertising