Campbell Scientific CR9000X Measurement and Control System User Manual

Page 146

Advertising
background image

Section 4. CRBasic – Native Language Programming

STRING

“AS STRING * size” specifies the variable as a string of ASCII characters,
NULL terminated, with size specifying the maximum number of characters in
the string. The minimum string datum size (regardless of word length), and the
default if size is not specified, is 16 bytes or characters. A string conveniently
handles alphanumeric variables associated with serial sensors, dial strings, text
messages, etc.

Strings can be dimensioned only up to 2 dimensions instead of the 3 allowed
for other data types. (This is because the least significant dimension is actually
used as the size of the string.)

Public FirstName AS STRING * 20
Public LastName AS STRING * 20

UINT2

Used for data storage only. Typical uses are for efficient storage of totalized
pulse counts, port status (e.g. 16 ports on an SDM-IO16 stored in one variable)
or integer values that store binary flags.

Float values are converted to integer UINT2 values as if using the INT
function. Values may need to be range checked since values outside the range
of 0-65535 will yield UINT2 data that is probably unusable. NAN values are
stored as 65535.

Binary format is useful when loading the status (1 = high, 0 = low) of multiple
flags or ports into a single variable, e.g., storing the binary number
&B11100000 preserves the status of flags 8 through 1. In this case, flags 1 - 5
are low, 6 - 8 are high. Program Code Example 4.2.4-8 shows an algorithm that
loads binary status of flags into a LONG integer variable.

EXAMPLE 4.2.4-8 CRBASIC Code: Program to load binary information into a single
variable.

Public FlagInt As Long
Public Flag(8) As Boolean
Public I

DataTable (FlagOut,True,-1)
Sample (1,FlagInt,UINT2)
EndTable

BeginProg
Scan
(1,Sec,3,0)

FlagInt = 0

For I = 1 To 8

If Flag(I) = true then

FlagInt = FlagInt + 2 ^ (I - 1)

EndIf

Next I

CallTable FlagOut

NextScan

EndProg

4-18

Advertising