Recommended Posts

Hello,

I have just downloaded the DAQFactory demo as an evaluation. I am currently trying to figure out if the program has all the necessary functions that we needed and was wondering if there is a good way to make three separate channels with their own persistent data. The first channel would be real time data taken in a five second interval, which I have already figured out. The second channel would take the five second data and roll it up into minute averages on the minute. Lastly the third channel would take the data from the second channel and roll the data up into hourly averages on the hour.

So far I have tried using the addvalue function in conjunction with the while loop supplied in the examples. However, I quickly found out that I could not do that due to the fact that the addvalue function autoloops itself and doing so crashes the program.

Therefore I would like to ask this community what solutions could I use.

Lexington

Link to comment
Share on other sites

AddValue() is the right course, but you can't addValue() within a channel event if you are adding to the same channel.

Probably the easiest way to do this is with two separate sequences. Let's say you have three channels called myChannel, myChannel5min, and myChannelHour. MyChannel I'm going to assume you've setup correctly and is reading live data. The other two are setup as Test channels with Timing = 0. Next, create two sequences. First, one for the 5 minute data:


while(1)
delay(300) // wait 5 minutes
private average = mean(myChannel[systime(), systime() - 299.999])
average.time = systime()
myChannel5Min.addValue(average)
endwhile
[/CODE]

Then create another sequence for the 1 hour data. Its identical to the first, except has a different delay:

[CODE]
while(1)
delay(3600) // wait 1 hour
private average = mean(myChannel[systime(), systime() - 3599.999])
average.time = systime()
myChannelHour.addValue(average)
endwhile
[/CODE]

That's it. The averages won't line up with the hour though. I'm going to assume that was not a requirement.

Also note that you can use the boxcar functions to do this sort of thing on the fly (for trending for example) However, if you want to log these averages, what you are doing is the correct choice.

Link to comment
Share on other sites

Its possible (most anything is possible! :) ), just slightly more involved:

private nextTime = floor(systime() / 3600) * 3600 + 3600  // start of next hour
while(1)
waituntil(nextTime)
private average = mean(myChannel[nextTime, nextTime - 3599.999])
average.time = nextTime
myChannelHour.addValue(average)
nextTime += 3600
endwhile[/CODE]

Link to comment
Share on other sites

Hi again,

So I tried the code that you suggested:

privite nextTime=floor(systime()/60)*60+60 //start of next minute
while(1)
waituntil(nextTime)
private average=mean(F7427[nextTime,nextTime-59.999]) //can't exactly be a minute
average.time=nextTime
F7427mm.AddValue(average)
nextTime+=60
endwhile

Where F7427 is the raw value and F7427mm is the minute approximation.

Only problem is when I run the code, DAQFactory freezes, much like how it was the first time I tried to implement a similar code.

Lexington

Link to comment
Share on other sites

You've got the channels linked up somehow outside the script. Can you post or email (support@) your .ctl doc so I can take a look? I'm sure its something simple.

Also, you spelled private wrong in the first line.

Finally, unless F7427 means something important to you, you might consider using a more descriptive channel name. Maybe even F7427BoilerTemperature or similar if you want to keep the association in the name. Often PLC's only support rather short, cryptic designations, but DAQFactory has no such limitation.

I've attached a sample showing it working. Its identical to your script, with private spelled correctly.

averageSample.ctl

Link to comment
Share on other sites

Archived

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