Logging data into a table. - old forum post


#1

phenning

Joined on 12-03-2007
Posts 1
Logging data on S-type controller

  • how do i set up logging from the control basic side and make the logs avaliable to the S-typpe controller

    Report
    12-05-2007, 11:41 AM
    rhernandez

Joined on 11-26-2003
Madrid - SPAIN
Posts 42
Re: Logging data on EB1 & accecing trhough S-type controller

Hello phenning,
In order to have a controller data-logging for you using PACControl you have to do all the work by yourself (all the work but collecting data :slight_smile: )
There are lots of ways to have a controller logging data, it depends on how much time you want to waste implemente features. Lets try to go for a minimum. Let’s try to record values from an Analog input named TT001, one sample per minute.

First you need to create a table, as big as you want/need, make it persistent so it recalls values across power losses (the limit is 512Kb, I believe). Say we call it TT001_log.
Next create a chart that controls the system time, detects when minutes change and when so, records one value. The following OptoScript code does the job (personally I prefer to split the following code in simpler blocks, but it will make it dificult to post an answer).
//loop for ever
while(1)
// wait until it’s time to log a value
while (nCurMinute<>nLastMinute)
DelaySec(1); //Give away time to other charts
// Get current time
nCurMinute = GetMinutes();
wend

// new minute: log value
ShiftNumTableElements(1,TT001_log);
TT001_log[0] = TT001;
// Memorize the time
nLastMinute=nCurMinute;
wend

Finally, modify your Powerup chart to start the above chart.

NOTE: Notice that new values will always go to element 0 of the logging table. This makes easy to know where the newest value on the table is. As time passes, old values will be “falling up” in the table, the last element in the table will be the oldest logged value. ShiftNumTableElements is an fast way to make room for a value (doing it “manually” with OptoScript code will be more than 10000 times slower).

Of course a lot of improvements can be taken into account but I think this is a good starting point.