Data Types
Data types define how a variable or value can be stored and accessed by the datalogger when running its program. Values within the datalogger can be defined as floating Four-byte floating-point data type. Default datalogger data type for Public or Dim variables. Same format as IEEE4. point numbers, integers,
Boolean Data type used to represent conditions or hardware that have only two states (true or false) such as flags and control ports., characters, or alphanumeric strings.
The following tables summarize the data types found in Campbell Scientific dataloggers for declaring variables and for final data storage. Note that not all data types are supported by all dataloggers. For example, the CR200(X) does not support declaring variables with data types and will return a compiler error if you attempt to define a variable as such. Also, the Double (or IEEE8) data type is not supported in the CR1000, CR800, and CR3000 dataloggers, although if it is used, the program will still compile. In this instance, the value is cast as an IEEE4 4-byte floating point value.
In addition to the tables below, refer to the Public and Dim instructions, which are used to define variables in the program, as well as the data table output instructions and string instructions for information on defining and using a specific data type.
Data Types for Variables
Data Type | Command | Description and Notes | Size (Bytes) | Range | Resolution |
---|---|---|---|---|---|
Float | As Float
(IEEE4) |
Single-precision
floating point number. Data type of all variables unless declared otherwise. |
4 | ± 1.1754943508∗10–38 tο ± 3.4028234664∗1038 |
24 bits (about 7 digits) |
Double | As Double
(IEEE8) |
Double-precision floating point number. Use to minimize floating point errors when doing floating point calculations or to store measurements of high-resolution digital sensors. Suitable for storing integers larger than |
8 | ±2.2250738585072014 *10-308 to ± 1.7976931348623157 *10308 |
53 bits (about 14 digits) |
Long | As Long
|
32-bit signed integer. Use to store integer data. Speed: integer math is faster than floating point math. Resolution: 32 bits. Suitable for storing whole numbers, counting numbers, and integers in final-data memory. If storing non-integers, the fractional portion of the value is lost. |
4 | –2,147,483,648 to +2,147,483,647 |
1 bit |
Boolean | As Boolean
|
Boolean, True/False, –1/0. A Boolean will never hold any value other than True or False (–1 or 0). Any non-zero numeric value or non-empty string written to a Boolean is stored as True (–1). Zero or an empty (nulled) string written to a Boolean is stored as False (0). |
4 | True = –1 False = 0 |
True (–1) or False (0) |
String | As String
|
Null-terminated array of characters. When using a very long string in a variable declared Public, the operations of datalogger support software will frequently transmit the entire string over the communication link. If communication bandwidth is limited, or if communications are paid for by the byte, declaring the variable Dim may be preferred. String size is defined by the CRBasic program. When converting from String to Float, numerics at the beginning of a string convert, but conversion stops when a
non-numeric is encountered. If the string begins with a non-numeric, the Float is |
Default word size is 4 bytes. Minimum: 3 + null terminator Default: 23 + null terminator Maximum = limited by available memory |
Unless declared otherwise, string size is 24 bytes or characters. String size is allocated in multiples of four bytes; for example, String * 25, String * 26, String * 27, and String * 28 allocate 28 bytes (27 usable). Minimum string size is 4 (3 usable). | |
UINT1 | As UINT1
|
8-bit unsigned integer.
Use to store integer data. Use to store port or flag status. When Floats convert to UINT1 at final data storage, values outside the range 0 – 255 yield unusable data. Note: Math using UINT1 has the same wrap around features of type UINT8 in “C”. Arrays of UINT1 variables can be used to store binary data received from serial sensors, which allows easier processing of that data compared to string variables when the responses may include NUL characters. UINT1 variables can be used as the destination in the SerialIn, SerialInBlock and SerialInrecord instructions. |
0 to 255 |
Data Types for Final Data Storage
Data Type | Argument | Description and Notes | Size (Bytes) | Range | Resolution | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FP2 | FP2
|
Campbell Scientific 2-byte floating point number. Default final-memory data type. Use FP2 for stored data requiring 3 or 4 significant digits. If more significant digits are needed, use IEEE4 or an offset. |
2 |
Minimum: ±0.001 Maximum: ±7999 |
|
||||||||||
IEEE4 | IEEE4
|
Single-precision floating point number. IEEE 754 |
4 |
±1.4E–45 to ±3.4E38 Consecutive Integer: ±224 |
24 bits (about 7 digits) | ||||||||||
IEEE8 | IEEE8
|
Double-precision floating point. Use to minimize floating point errors when doing floating point calculations or to store measurements of high-resolution digital sensors. Suitable for storing integers larger than |
8 |
±4.94065E-324 to ±1.79769E308 Consecutive Integer: ±253 |
53 bits (about 14 digits) | ||||||||||
Long | Long
|
32-bit signed integer. Use to store integer data. Speed: integer math is faster than floating point math. Resolution: 32 bits. Suitable for storing whole numbers, counting numbers, and integers in final-data memory. If storing non-integers, the fractional portion of the value is lost. |
4 | –2,147,483,648 to +2,147,483,647 | 1 bit | ||||||||||
UINT1 | UINT1
|
8-bit unsigned integer.
Use to store integer data. Use to store port or flag status. When Floats convert to UINT1 at final data storage, values outside the range 0 – 255 yield unusable data. |
1 | 0 to 255 | 1 bit | ||||||||||
UINT2 | UINT2
|
16-bit unsigned integer.
Use to store integer data. Use to store port or flag status. When Floats convert to UINT2 at final data storage, values outside the range 0 – 65,535 yield unusable data. |
2 | 0 to 65,535 | 1 bit | ||||||||||
UINT4 | UINT4
|
32-bit unsigned integer. Use to store positive count data. Other uses include storage of long ID numbers (such as those read from a bar reader), serial numbers, or address. May also be required for use in some Modbus devices. |
4 | 0 to 4,294,967,295 | 1 bit | ||||||||||
Boolean | Boolean
|
Boolean, True/False, –1/0. Use to store true or false states, such as states of flags and control ports. Any non-zero numeric value or non-empty string written to a Boolean is stored as True (–1). Zero or an empty (nulled) string written to a Boolean is stored as False (0). To save memory, consider using UINT1, UINT2, or BOOL8. |
4 | True = -1 False = 0 |
True (-1) or False (0) |
||||||||||
Bool8 | Bool8
|
Array of eight 1-bit Boolean values. Memory-efficient method for storing and transferring up to 8 Boolean values. Datalogger support software expands this out to 8 individual table fields. |
1 | True = -1 False = 0 |
True (-1) or False (0) |
||||||||||
NSEC | NSEC
|
Time stamp. Divided up as four bytes of seconds since 1990 and four bytes of nanoseconds into the second. Used to record and process time data |
8 | Seconds since 1990 | 1 nanosecod | ||||||||||
String | String
|
ASCII string. When using a very long string in a variable declared Public, the operations of datalogger support software will frequently transmit the entire string over the communication link. If communication bandwidth is limited, or if communications are paid for by the byte, declaring the variable Dim may be preferred. String size is defined by the CRBasic program. When converting from String to Float, numerics at the beginning of a string convert, but conversion stops when a non-numeric is encountered. If the string begins with a non-numeric, the Float is |
Minimum: 3 (4 with null terminator) Default: 24 Maximum: limited only to the size of available memory. |
Unless declared otherwise, string size is 24 bytes or characters. String size is allocated in multiples of four bytes; for example, String * 25, String * 26, String * 27, and String * 28 allocate 28 bytes (27 usable). Minimum string size is 4 (3 usable). |
*As a special case, a string can be declared as String * 1. This allows the efficient storage of a single character. The string will take up 4 bytes in memory and when stored in a data table, but it will hold only one character.
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.) To begin reading or modifying a string at a particular location into the string, enter the location as a third dimension; for example, String(x,y,n)
where n is the desired character. For example, given an array of strings Str(10,10)
, Str(2,2,n)
refers to n character in the (2,2) element of the array. Use Str(1,1,n)
for a scalar variable and Str(x,1,n)
for a dimensional array element.