Recommended Posts

Hi Firstly a really simple question,

where do i put expressions like Test = channel1+channel2 and then do some things with Test, Do i make Test a channel, if so what is the I/O set to. sorry its so basic but im a little lost.

Do you have a libary of example routines that can be downloaded and played with to help with the learning process for us novices.

Finally can you give me a little advise with my calculations as per a post in Graphs in August. I want to sum a channels value over 1 Hour (3600 samples) then say call that value H1, then start all over again for the next hour (H2) up to 24 Hours starting from Midnight.

Its all to do with my home micro generation using wind & Solar.

Thank you for your patients, i get very little time to play


Link to comment
Share on other sites

Well, why do you want to create Test? You can type Channel1 + channel2 into just about any screen component, even graphs. DAQFactory is not like Excel, or many other packages where in order to work with calculated values you have to create a variable for it. DAQFactory will calculate it for you on the fly.

That said, there are two reasons why you might want to do what you ask:

1) You actually don't want channel1+channel2, but want something much more complicated and didn't want to type it in here, and don't want to have to type it in every time you want to access it. For this, you might consider using a calculated V channel. Create a new channel under V and put Channel1 + Channel2 in the express. Then you can access the calculated result with V.Test where Test is the name of the V channel you made

2) You want to do some other manipulation of the data and actually need it in a variable. Then you need to do it in script somewhere. First you need to declare Test, then you can do the assignment. Note that the assignment is a snapshot when its executed and Test will not continually update with the sum of Channel1 and Channel2 like the V channel and the direct expression method will (which is another reason for doing it this way, for example if you want to capture a background setting). The script would look like this:

Global test
test = channel1 + channel2

You can then access test like a channel, just by specifying its name.

Library of example routines? You can look at the sample apps, and read the posts. I definitely recommend going through the guided tour, and then maybe read the first few chapters on Expressions and Sequence Scripting.

Sum channels: do you want it on the hour or just the last 3600 points? The easiest way is to calc as the data is coming in. Since I don't think you care, I'll show you the easy, but slightly less accurate way. Let's say your channel is called PowerIn:

1) Create a new channel called HourlyPower. Device Type Test. Timing = 0. Rest doesn't matter.

2) Go to your PowerIn channel (click on it in the workspace), then select the Event tab.

3) Enter script like this:

if (formatdatetime("%H",PowerIn.Time[0]) != formatdatetime("%H",PowerIn.Time[1]))

The if() statement is comparing the hour portion of the time of the most recent reading and the next most recent reading, and if they are different, we are adding the sum of the last 3600 seconds of data to hourlypower. This is the inaccurate part. Technically, we are getting slightly into this hour. So, instead of being 11:00:00 to 11:59:59, its more like 11:00:01 to 12:00:00 (assuming 1 second data).

I did two common DAQFactory techniques:

1) I used formatdatetime() to determine when the hour ticked over. This is useful for day, week, month, etc. as well.

2) I use subsetting by time instead of index. You could do [0,3599] (subsetting by index) since you know your data is once a second, but if data was missed, you'd end up picking up more than an hours worth. So, instead, we subset by time, specifying the start and end time we want. Then it will sum however many datapoints there are within the range.

Finally, to access the data, just look at HourlyPower. HourlyPower[0] is the last hour total. HourlyPower[1] is the hour before that, etc. You can set the history to 24 if you only want 24 hours, but why not use the Channel Persist set to something big and be able to review totals back in time easily. Even a value of 8760 gives you a years worth of totals, and that's still a small amount. Use persist though to ensure the totals remain if you restart DAQFactory.

Link to comment
Share on other sites

Wow thanks for your time and advise, time to start doing and trying i feel.

Thanks once again


Link to comment
Share on other sites

Alas, i have done all you suggested and by using Watch i can see my corrected data (Powerin) and this i can plot.

I set up the second hourlypower channel as suggested with the code cut and pasted in event but nothing happens. The Row, Time, Vaue Fields are also empty. When i go to graph in the hourlypower channel page it starts at 1st Jan 70. In Watch there is no value and when i try to plot or display hourlypower the expression box stays red in both 2D graph and as a variable.

Any pointers on what i have done wrong. Once i get something working i can build on it.

Once again many thanks and sorry for my lack of ubderstanding


Link to comment
Share on other sites

Hi again, didnt have much wind today but i had no results i have attached my file. For each of the hourlypower i received "C1000 channel or function not found"

Thanks again



Link to comment
Share on other sites

I'm afraid you skipped step 2. The event code goes in the PowerIn channel, not the hourlypower. Events get called whenever new data arrives. Since HourlyPower only gets new data when the event script is called, putting it inside its own event does nothing.

Link to comment
Share on other sites


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