Graphing Variables (how to assign times to variables)


dmdodd

Recommended Posts

So I have a variable that is calculated in a looping sequence from a number of different channel inputs (temps, pressures etc), and is stored in a global variable, which I can happily display on the screen.

I know that for variables to be used on graphs, you need to be able to assign time to each data entry also (to create a history), I just can't seem to get it to work.

I've read the guide and it talks about using inserttime() or gettime() etc, I'm just confused as to how to add this into the array - along with the "addvalue()" command?

When I use the following in the command line:

? mass_flow_rate_history

it prints back an array, {0, 0, 19.4, 19.5, 20, 0, 0} etc, so that's half the battle no? At least it's getting the variable into the array, I just want to be able to add time to it so I can plot these variables.

Thanks in advance,

Daniel D

Link to comment
Share on other sites

The easiest thing to do is use a Test D to A channel. Then you can just do:

mass_flow_rate_History = x

to add the value x to the channel and thus create history and a time stamp. However, with variables, just use insertTime() and addvalue():

mass_flow_rate_history.addvalue(insertTime(x, systime(),0))

Link to comment
Share on other sites

I can't use a channel for this, as I don't have many left for I/O requirements, so that's why I want to be able to do this using variables.

I'm using the following code:-

syngas_MassFlow_SCFM_SType_Hist.addvalue(insertTime(syngas_MassFlow_SCFM_SType, systime() , 0))

Unfortunately that method doesn't work perfectly, it's giving charts that look saw-tooth in nature (I'll try an attach a screenshot). What is the "0" in your recommended code for? Is that what's dropping the chart back to zero each time.

Update (Chart 2): I don't know what's happening, I changed the graph to show negative values (on y-axis) and now it's showing the other attachment, and it's not even showing the correct value (upper points on saw-tooth chart 1).

You'll also notice the first chart only displays a few seconds (~20s) of data, I've tried increasing the history length using:

syngas_MassFlow_SCFM_SType_Hist.HistoryLength = 10000

I read in the manual that "Data will build up until the history length for the variable is reached. The default history length for a variable is 3600. To change, set the HistoryLength parameter of the variable to the new value, fox example: MyVariable.HistoryLength = 100" So I'm assuming I need to increase the allowable history length, but you wouldn't have thought it would use-up 10,000 slots in the array in 20 seconds!

post-7954-1316192245_thumb.png

post-7954-1316193887_thumb.png

Link to comment
Share on other sites

I can't really say what is going on without more information. If your loop is fast, you could use 10,000 slots in 20 seconds. I still say that Channels are much easier way to go, and not wanting to upgrade is not really a good excuse. You are basically asking for support to get around paying us (a rather small amount of) money.

Link to comment
Share on other sites

Ha, in fact to screw Azeotech out of a $300 upgrade fee wasn't my motivation at all.

I'd actually read that using variables is actually quicker and less data intensive as channels go through all sorts of "broadcasting, alarming" etc. and variables do not.

I also thought it may be useful for other DAQFactory users out there to see how to graph variable using generated histories, I bet a number of small users (home brewers, university projects etc) can't upgrade as easily as real companies to "unlimited channel" licenses, but would still like to use all their channels for I/O and therefore variables for other data processing and displaying.

I'll use one of my 64 channels for now, but it won't solve my need of graphing global variables in the future.

FYI, I have a statement "delay(2)" at the bottom of the while loop, before "endwhile", so I'd have thought it should be impossible to use 10,000 array slots in 20 seconds, if I'm constraining the loop to run only every 2 seconds.

Thanks again,

Daniel D.

Link to comment
Share on other sites

Sorry, but you'll see in some other posts here that, in fact, the intention is to avoid paying AzeoTech any money (usually people using the free Express and not wanting to upgrade). AzeoTech is a small company, not "the man", and our software is really quite affordable, so I have little patience for it. Anyhow, my apologizes on getting on your case.

I can't really address what you are seeing without seeing your script. Its possible that you are inadvertantly adding an array to the variable. In fact, this probably would explain the zig-zag in the graphs. The thing to remember is that AddValue() works with both arrays and scalars. If you do:

x.addvalue(1)

it will add the scalar 1 to x and the history of x will increase by 1. If, however, you do:

x.addvalue({1,2,3,4})

it will add all 4 values to x, in that order, and the history of x will increase by 4. If you are using a calculation, my guess is you referenced a channel in it and forgot to use [0]. So you did something like:

x.addvalue(mychannel * 4)

when you should have done:

x.addValue(mychannel[0] * 4)

If you forget the [0], then you are adding the entire history of mychannel to x each iteration.

Link to comment
Share on other sites

Looks like maybe you need to "inserttime" of a value that ALL your variables increment on and not just systime()...

mass_flow_rate_history.addvalue(insertTime(x, rate.time[0],0))

To get the graph to display properly, all the values shown need to have a good solid time that all values "increment" on...

HTH and hope I am not leading you wrong!

I see you're from Sacramento!

Cool to see a neighbor using DF...(AzeoTech is the master, ask the right questions, and you will get the right answer!!)

:)

Link to comment
Share on other sites

Archived

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