Reset counter channel for new *.csv file


Seedywee

Recommended Posts

I want to log a tipping bucket rain gauge on the U3 counter channel. Each tip measures 0.2 mm rain.

I can see the instructions on how to produce a new *.csv file at midnight. What's the best way to reset the rain counter at midnight to get daily rainfall?

Thanks!

Link to comment
Share on other sites

Thank you for your reply. My question is hypothetical. I want to find out in advance how suitable the U3 is for measuring daily rainfall before I buy it.

I'm selecting DAQFactory Express over LJLogUD because I can see in the DAQFactory manual that it's possible with some simple code to get a new daily *. csv file at midnight. I don't know whether cumulative counting is done in the U3 or in DAQFactory and would appreciate guidance.

Thanks.

 

Link to comment
Share on other sites

If you use "Logging" and if you know the number of records per day, you can set "Auto Split Files" in the "Details" contribution and set the number of lines in the file to "Data File Size". As soon as the specified number of rows of data are written to CSV-file, a new file will be created.

Link to comment
Share on other sites

Personally I prefer doing the accumulation in DAQFactory, rather rely on the counter.  This allows you to use Persist to maintain the counts between restarts.  To do that, you create two channels, one that does the raw reading, and the other that holds the accumulated counts.  Then you can add all the logic you need.  It would all lie in the Event for the raw reading channel.  Let's say that one is called "RawCounts", and the other is called "Rainfall".  RawCounts is a LabJackUD counter channel, and you can see the required setup to make it a counter channel in the DAQFactory - LabJack Application guide, along with its sample.  Rainfall is a Test A/D channel with Timing = 0.  In the Event for RawCounts, to do the accumulation you would do:

RainFall.addValue(insertTime(rainfall[0] + RawCounts[0] - rawCount[1]), rawCounts.time[0],0)

To reset the rain fall count, before the above line add some logic to look for the end of the day:

if ((rawCounts[0] % 86400) < (rawCounts[1] % 86400))
   rainFall.addValue(0)
endif

% is the modulus operator, which gives you the remainder of division.  % 86400 then gives you the # of seconds into the day.  When the most recent reading has a smaller seconds into the day then the previous reading, then we've moved to a new day and we should reset the count.  In this system, we never reset the LabJack's counter, except maybe at startup.  The final event script then looks like:

if ((rawCounts[0] % 86400) < (rawCounts[1] % 86400))
   rainFall.addValue(0)
endif

RainFall.addValue(insertTime(rainfall[0] + RawCounts[0] - rawCount[1]), rawCounts.time[0],0)

Link to comment
Share on other sites

While Morales idea is good, it is not really the best way to get daily files.  The issue is two fold, first you can't always be sure how many data points you'll get in a day.  A missed reading will throw the logic off.  Second, you can't tell what time of day the log will start.  The best way to do it is to inject the date/time stamp into the file name.  For daily logs, you would only inject the date, not the time.  In newer versions of DAQFactory this can be done right in the filename of the logging set.  Whatever you type there is basically passed to the formatDateTime() function with the current system time to form the current file name.  If you specify a date, then every day, the file name will change and a new file will be created. 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.