Recommended Posts

Is there example code for:

1) Using computed data added into a Virtual Channel with Time;

2) That can then drive a Graph Trace 'real time';

Need this in a testbed to investigate why a Persistent Max value drops once the Peak Value shifts out of History instead of Persisting.

Share this post


Link to post
Share on other sites

I personally prefer just creating a Test channel (with timing 0).  Then, use AddValue() on that channel to stuff my calculated data into it.  Graphing it then is no different then graphing anything else.

So, if you had a test channel called "calcedValue" and you wanted to stuff some calculation in there based on a channel called "myChannel", you might go to the Event for myChannel and put:

calcedValue.addValue(myChannel[0] * 10)

Sometimes it can get tricky with the time stamp, so I often force it:

calcedValue.addValue(insertTime(myChannel[0] * 10), systime(), 1)

 

 

Share this post


Link to post
Share on other sites

Thanks for your timely reply!

If i do not have a data-driven Channel to use its Event for a trigger, what technique will generate one?

Share this post


Link to post
Share on other sites

If its not driven by Timing, its got to be driven from somewhere.  You are filling your V channel from somewhere, right?  Just add it to that code.

Share this post


Link to post
Share on other sites

I had already switched to a Test Channel, as you advised.  Attempting to drive from a sequence to generate the data to exercise control over the value stream.

Will attach .ctl file, but be aware I'm still debugging a C1099 error (in line 5 of DataSource).

Frankly, I'm loathe to send you the code I'm supposed to be developing, but up against a looming test session on many product samples.

This TestBed was intended to provide a known-data driver to work out why the MaxPersistent code is malfunctioning in our primary testing tool, but I'm suffering from cascading ignorance ...

TestBed.ctl

Share this post


Link to post
Share on other sites

Hi Guru...referencing the Test device above led me to a question.  Is it possible to rename the device to something like "Internal".  The reason I'm asking is that "Test" to me is more like a temp channel for testing purposes and is not a permanent channel..  To me it would be better to name is something like "Internal" or something that indicates that it's a permanent channel.

Can it be renamed?

Thanks...John

Share this post


Link to post
Share on other sites

The problem with line #5 is parenthesis location.  I'm sorry I didn't see it in your other posts.  InsertTime() takes three parameters.  You have only one inside the inner (), and then two additional parameters, systime() and 1, inside the outer ().  The inner () is for InsertTime, and the outer () is for AddValue().  Its giving you an operator error because you provided too many parameters to AddValue.

And John: yes, you can rename it if you want.  Just go into testDevice.dds and change the "Test" in the line that reads:

D,0,Test,TestDevice.dll,O

to whatever you want.  Don't change anything else on that line.  Note that this could cause incompatibilities with other DAQFactory applications, etc.  We named it "Test" because originally it was designed for creating test applications without any real hardware.  But, it became useful as a place to stuff data.  And come to think of it, rather than renaming it, you might consider just copying testDevice.dds to say internalDevice.dds and then make the change I recommended, but also changing the 0 to something bigger, like 1000.  Don't change TestDevice.dll, just let both dds files point to the same dll.  Then you'll have two different devices, one named "Test" and one named "Internal" or whatever you want.  They will act the same way because internally they are the same driver.

Note that any time I use a Test device and stuff data in it, you can use any other device you want from the drop down.  As long as the Timing is set to 0 and you never do read() or readGroup() or myChannel = then the driver is never called.  I often do this if I'm using "Test" type channels with real hardware, say, for a calculated value from a real channel.  But for this forum, I try and stay consistent and recommend "Test"

Share this post


Link to post
Share on other sites

Presumably none of the attempts I've made to display the Test Channel on the Graph Component in the attached .CTL have succeeded because the Test Channel Timing is set to 0, which is necessitated by the method used to fill it with computed values?

Should Test.Event be used in some way to drive a Graph Trace?

TestBed.ctl

Share this post


Link to post
Share on other sites

Actually, they probably failed because your sequence didn't work and so no data was being added to the channel.  Once I fixed the parenthesis issue and ran your sequence, the graph you have on the page started showing a trend.  This is because you used insertTime() to put a time stamp on each data point being added.  Graph's don't care how the data was generated, they just need an X and a Y, or in the case of a trend graph, a Y and corresponding Time, which you created with insertTime(), and truthfully would be created anyway just with AddValue() because a regular channel HAS to have time associated with all values.  The problem is that depending on the math, you can create a situation with addValue() where the time stamp remains the same, and that can't really be graphed, or at least would result in a vertical line.

Timing is just an easy way to tell DAQFactory to query a channel every so often.  

Share this post


Link to post
Share on other sites

Hey Guru...duplicated TestDevice.dds and created a internal.dds with the changes you directed.  Works great!!!

One additional question...Under the I/O Type, I see standard data types like string, but not some of the other data types such as int, float, and Boolean.  What I/O type should I use for these types?

John

 

Share this post


Link to post
Share on other sites

There are only two data types in DAQFactory.  Number and string.  Number is a double precision float, so really covers all the other typical numeric types except 64 bit integers.

Share this post


Link to post
Share on other sites

Thanks Guru...I did not know that but makes sense.

 

John

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now