CardOut (Save New DataTable to a Memory Card)
The CardOut instruction is used to create a new DataTable that will be saved on a memory card (CRD drive).
Note, when storing high-frequency data, or when storing data to cards greater than 2 GB, the TableFile instruction with Option 64 may be a better method to write final storage data to a card. For more information, see Methods for Writing Data to a Card.
NOTE: Although modern Campbell Scientific data loggers format storage media using FAT32—which can support individual files up to 4 GB—the CardOut() and Tablefile() instructions are still limited to a maximum file size of 2 GB. This limit exists not because of the file system, but because of how the data logger firmware internally tracks file lengths. Campbell Scientific data loggers use a signed 4-byte integer to represent file sizes in the directory table. A signed 4-byte integer has a maximum positive value of 231−1, which is approximately 2 GB. Because the underlying firmware uses this data type, no file created through CardOut(), TableFile(),or any other file creation method can exceed 2GB—even if the storage device and file system (FAT32) would otherwise allow larger files.
Syntax
The following example shows the use of the CardOut instruction to store a DataTable to a memory card. 1000 records will be stored to the card; it is formatted as ring memory.
Public Batt_volt, RefTemp, TCTemp
DataTable (Table1,True,-1)
DataInterval (0,1,Min,10)
CardOut
(0,1000)
Sample (1,Batt_volt,FP2)
Sample (1,TCTemp,FP2)
EndTable
BeginProg
Scan (1,Sec,3,0)
Battery(Batt_volt)
TCDiff (TCTemp,1,mv200C,U1,TypeT,RefTemp,True,0,15000,1.0,0)
CallTable (Table1)
NextScan
EndProg
Remarks
A CardOut instruction must be included in each DataTable declaration for which data should be written to a memory card. The data table is saved to both the data logger’s internal memory and the card. The internal memory acts as a buffer, and when enough data accumulates, it is flushed to the card. This results in duplicate data—up to the internal table size—existing in both internal memory and the card file.
Data is written to the card in binary TOB3 format, with a filename consisting of the data logger’s Station Name (if assigned), the DataTable name, and a .DAT extension: E.g., stationname.tablename.dat
The file is dated based on the time the program was compiled in the data logger.
-
If the TOB3 file is copied directly from the card to a PC, the binary data must be converted to a human-readable format using CardConvert (included in LoggerNet, PC400, PC200W, and other software).
-
If the data table is collected using LoggerNet or other data collection software, it can be stored in TOA5 or other ASCII formats.
The file on the card extends the table memory. When table data is retrieved—via LoggerNet or the TableFile instruction—the data logger searches internal SRAM first, then the card.
-
If a file with the same name exists on the card, data is appended only if the file header matches.
-
Header checks include: model type, serial number, station name, program name, and all table field information.
To match, the file must have been created on the same data logger using the same program, with no changes to the table. If the file is not identical, a compile error occurs, and no data is stored to the card. To resume card storage, either delete the old files or rename the new table in the program.
Optionally, the data logger can automatically delete card files with non-matching headers using the DeleteCardFilesonMismatch setting in the data logger. For example" SetSetting("DeleteCardFilesonMismatch", -1).
StopRing (Specify Data Table Type)
Specify whether the DataTable created should be a Ring Mode table (0) or a Fill and Stop table (1). In Ring Mode, once the number of records reaches the specified size, new records are stored over the oldest records. For Fill and Stop, when the table is full no more data is stored.
Type: Constant
Size
Defines the number of records (or rows) that should be allocated for the DataTable. The number of values (or columns) in the DataTable is determined by the output processing instructions contained in the DataTable declaration. Size can be defined as a fixed number of records or as auto-allocate. To set the table size to a fixed number of records, enter that value. To set the size to autoallocate, enter a -1. If a table is set to auto-allocate, all memory that remains after creating fixed-sized tables will be allocated to this table. If multiple DataTables are declared with a -1 for size, the available memory will be divided among the tables. The datalogger attempts to allocate memory to the tables so that all tables are filled at the same time. By default, data storage memory sectors are organized as ring memory. When the ring is full, oldest data are overwritten by newest data. Using the FillStop statement sets a program to stop writing to the data table when it is full, and no more data are stored until the table is reset.
For the CardOut instruction, enter -1000 to set the size of the data table on the card to the size of the data table in datalogger memory.
NOTE: For extended-memory dataloggers, auto-allocated data tables are written automatically to the extended internal memory (72 MB) unless CardOut() or Tablefile() is used. When CardOut() or Tablefile() is used, data is streamed from the CPU to the card in 1 KB frames, and the extended internal memory is not utilized. As a result, on extended-memory dataloggers, auto-allocated table fill times on the CPU are longer if CardOut() or Tablefile() is not used. However, total final data storage is greatly increased with external memory, allowing up to 2 GB per table. To check whether a datalogger has extended internal memory, view the CPU Bytes Free in File Control. Dataloggers with extended internal memory display approximately 30 MB Bytes Free for an empty CPU, compared to about 1 MB Bytes Free for dataloggers without extended internal memory.
Type: Constant (or expression that evaluates as a constant)
NOTE: If CardOut is set to Fill and Stop, when data storage stops in the card it will also stop in the data table, regardless of whether the data table in the data logger is configured as fill and stop or has reached its maximum number of records. Similarly, if a data table is set to Fill and Stop, when data storage stops in the table it will also stop in the card.
See the following videos for additional information on using microSD cards with Campbell Scientific data loggers:
Fundamentals of CRBasic Programming Part 8: Deploy, Monitor, and Swap MicroSD Cards in the Field
Fundamentals of CRBasic Programming Part 9: Retrieving Data from a MicroSD Card