Campbell Scientific CR9000X Measurement and Control System User Manual

Page 136

Advertising
background image

Section 4. CRBasic – Native Language Programming

The structure of a CRBasic program requires that variables and subroutines be
defined before they can be used. The best way to do this is to put all the
variable declarations and output table definitions at the beginning, followed by
the subroutines, and then the program. Table 4.2.3-1 describes the structure of
a typical CR9000X program. Example Program 4.2.3-1 and 4.2.3-2 show
examples of following correct program structure.

TABLE 4.2.3-1: Program Structure

Declarations

Define datalogger memory usage. Declare constants, variables,

aliases, units, and data tables.

Declare constants

Declare fixed constant variables to their values

Declare Public variables

Declare & dimension Public Variables(variables that will be

viewable using real-time monitoring during program execution)

Dimension variables

Declare & dimension variables not viewable during program

execution.

Define Aliases

Assign aliases names to variables.

Define Units

Assign engineering units to variable (optional). Units are strictly for

documentation. The CR9000X makes no use of Units nor checks
Unit accuracy.

Define data tables.

Describe, in detail, stored data tables.

Process/store trigger

Set when the data should be stored. Are they stored when some

condition is met? Are data stored on a fixed interval? Are they
stored on a fixed interval only while some condition is met?

Table size

Set the size of the table in CR9000X RAM

Other on-line storage devices

Should the data also be sent to PC card or Flash memory?

Processing of Data

What data are to be output (current value, average, maximum,

minimum, etc.)

Define Subroutines

If there is a process or series of calculations that need 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. Can include measurement Scans for conditional
measurements

Begin Program

BeginProgram defines the beginning of the statements that define

datalogger actions

Set scan interval

The Scan instruction sets the interval for a series of measurements

Measurements

Enter the measurements to make

Processing

Enter any additional processing

Initiate controls

Check measurements and Initiate controls if necessary

Call Data Table(s)

Declared Data Tables must be called to process and store data

NextScan

Loop back (and wait if necessary) for the next scan

End Program

4-8

Advertising