How do you catch a unique bird?
You 'neak up on it.
How do you catch a tame bird?
The tame way.

Ha ha ha! That cracks me up every time. “What does that have to do with datalogging?” you ask. Most of the time data is stored on a time interval using the DataInterval() instruction. But, sometimes you want to store data under unique conditions. This is referred to as conditional data, and the DataEvent() instruction, which is a DataTable() modifier, is one way to accomplish it. This is what the CRBasic editor help says:

The DataEvent instruction is used to conditionally start and stop storing data to a DataTable. Trigger events can be specified to determine when data storage begins and when data storage ends. Additionally, a number of records to store before and/or after the event can be specified. 

For example, let’s say you are measuring and storing temperature data. You take measurements every second and store data every hour. If, in addition to these data, you also want to store every one-second measurement when the temperature exceeds a set value, you can use the DataEvent() instruction.

There are four arguments in the DataEvent() instruction: Records Before, Start Trigger, End Trigger, and Records After. Let’s talk first about the Start Trigger (StartTrig). Start Trigger is a constant, variable, or expression to be evaluated for starting the data storage event. In our example, we could use an expression such as TempC > 25. When the variable TempC exceeds 25, the StartTrig argument is true and the data storage event starts. Likewise, the End Trigger (EndTrig) is a constant, variable, or expression to end the event. In our example, we could use TempC < = 25 to stop storing data when the temperature falls below 25. The instruction would look like this:

     DataEvent (0,TempC >25,TempC < =25,0)

The start and end triggers can be unrelated. You could have the start trigger based on temperature and the end trigger based on some other variable such as wind speed.

Records Before and Records After the event let you capture data before and after the start and end triggers are met. No, the datalogger doesn’t know when an event is going to occur before it does. It sneaks up on it by keeping a buffer of the data in memory in case a data event is triggered. In our example, we’ll store 30 records before, and 15 after. The complete DataTable may look something like this:

     DataTable (Event,True,1000)
         DataEvent (30,TempC >25,TempC < =25,15)
         Sample (1,TempC,FP2)
     EndTable

It is important to specify the number of records in a conditional data table: DataTable (Event,True,1000). For more information, see the Data Table Memory Allocation tutorial at www.campbellsci.com/19_1_9999_153 and my article on compiled program details at www.campbellsci.com/tips-details.

Give the DataEvent() instruction a try when you need to catch some unique data. Use the Records Before argument to sneak up on it, and never miss a special event.

Uniquely yours,