2 program declarations, 2 program, Declarations -21 – Campbell Scientific PC400 Datalogger Support Software User Manual

Page 183

Advertising
background image

Section 9. Datalogger Program Creation with CRBasic Editor

Define Subroutines

If there is a process or series of calculations

that needs to be repeated several times in the
program, it can be packaged in a subroutine
and called when needed rather than repeating
all the code each time.

Program

The program section defines the action of

datalogging.

Set scan interval

The scan sets the interval for a series of

measurements.

Measurements

Enter the measurements to make.

Processing

Enter any additional processing with the

measurements.

Call Data Table(s)

The Data Table must be called to process output

data.

Initiate controls

Check measurements and Initiate controls if

necessary.

NextScan

Loop back (and wait if necessary) for the next

scan.

End Program

9.4.2 Program Declarations

Variables must be declared before they can be used in the program. Variables
declared as Public can be viewed in display software. Variables declared using
Dim cannot be viewed. Variables assigned to a fixed value are used as
constants.

For example, in a CRBasic program there may be multiple temperature (or
other) sensors that are wired to sequential channels. Rather than insert multiple
instructions and several variables, a variable array with one name and many
elements may be used. A thermocouple temperature might be called TCTemp.
With an array of 20 elements the names of the individual temperatures are
TCTemp(1), TCTemp(2), TCTemp(3), ... TCTemp(20). The array notation
allows compact code to perform operations on all the variables. For example,
to convert ten temperatures in a variable array from C to F:

For I=1 to 10
TCTemp(I)=TCTemp(I)*1.8+32
Next I

Aliases can also be created that will allow an element of an array or another
data result to be referred to by a different name. To continue the example
above, TCTemp(3) could be renamed using the following syntax:

Alias TCTemp(3) = AirTemp

In the display software, the more descriptive alias, AirTemp, would be used for
the cell name.

9-21

Advertising