Recommended Posts

I have a channel which I graph in a regulaur graph with the expression "POND_DIR[sysTime(), SysTime()-86400]" and it graphs OK. I also graph this channel in a "SLIDER/ KNOB" graph using the expression "POND_DIR[s,e]" and it graphis OK.

In the sequence that reads this data into DAG, I calculate "POND_DIR_C = 360 - POND_DIR" and POND_DIR_C is a global variable.

POND _DIR_C[sysTime(), SysTime()-86400] or POND_DIR[s,e] will not graph. you helped me set up the scripting so I do not fully understand [sysTime(), SysTime()-86400] or [s,e].

What am I doing wrong; I have waited tackling this problem waiting for version 6 release but it doesn't seem to be arriving and I have to fix the issue.

Attached is the *.ctl file

Help appreciated


Link to comment
Share on other sites

OK, first you don't really need the [systime(), systime()-86400]. The Time Width parameter of the graph will take care of the subsetting. I don't remember what the [s,e] was for, but I'm guessing for getting a different time range, perhaps from an older version where there were less choices. Now you can change the graph scaling directly from script by naming the graph.

But that isn't the problem here. Here the problem is that POND_DIR_C is a test channel channel and you are doing:


POND_DIR is an array because its a channel that has history. POND_DIR + 120 is also an array, where each element of POND_DIR has 120 added to it. The problem is that you are assigning this to a test channel. For one thing, its a A to D test channel, and assigning an A to D test channel a value simply causes it to think it should generate its test value, which is a number between -1 and 1. If it was a D to A test channel, it actually would probably work correctly, except for the if statement. With D to A test channels, doing:

chan = 3

will add 3 to the history of chan. But you then look at chan and set it to something else:

if (POND_DIR_C > 360)
   POND_DIR_C = 360 - POND_DIR_C

Well, the problem is that now you've added two values, the original calculated value, and this value adjusted for being over 360.

The other problem is that you really should be subsetting with [0] on channels when you want to work with scalars. When you do POND_DIR_C = POND_DIR + 120, you are adding to all the historical values as well. You really want: POND_DIR_C = POND_DIR[0] + 120, so it just does the last value.

That said, you need somewhat different logic here anyway. You need to use a private variable:

private pondDirC = POND_DIR[0] + 120
if (pondDirC > 360)
   pondDirC = 360 - pondDirC

You can leave POND_DIR_C as an A to D test channel with this script. What I do is calculate the value and do my check on a private variable. Then, once I have the proper value, I use the AddValue() function, just like you did on the othe channels, to stuff my result into POND_DIR_C.

Link to comment
Share on other sites

Version 5.83 build 1632.

You are correct; I had a global variable and channel with the same name.

Can you help with supplying an example of of changing the graph scaling in script by naming the graph.

Again thanks

Link to comment
Share on other sites

Sure. Let's say you named your graph myGraph by right clicking on it and selecting Component name.... To change the time width of the bottom axis to a day, you'd do:

component.mygraph.BottomAxis.strTimeWidth = 86400

There are lots of other variables both for graphs and other components. They are listed in the help, or you can usually see them as you type the command.

Link to comment
Share on other sites

Thanks again, but where do I enter "component.mygraph.BottomAxis.strTimeWidth = 86400". I tried adding it to the "TIME WIDTH" window in the graph-properties-axes-bottom axex window but nothing changer. I tried ading iot to a sequence but nothing happened???

Sorry I'm so thick.

Link to comment
Share on other sites

It would go in a sequence, but you'd have to run the sequence to have it execute. If you are always just going to use Time Width and you just want it variable, you could put a global variable's name in the Time Width window and then just change that global variable.

Link to comment
Share on other sites


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