09-29-2005 03:00 AM
I am using the attached sub vi to return max, min, and average values received from a plc on our factory floor. The data in the sub vi is analysed every time the value in the plc changes rather than analysed after a set time delay. I have programmed the sub vi to output the data to the main vi after 20 values have been collected, however as soon as the sub vi starts outputting, the rate of the sub vi accelerates to the speed of the main vi rather than outputting every time a new value is received from the plc. This means my averages are calculated and outputted incorrectly.
Is there any way to control while loop in the main vi so that it only executes when fresh data is available from the sub vi? I have tried the LV help files on loops and structures but haven’t found anything relevant yet.
Regards,
Stuart Wilson
09-29-2005 03:14 AM
Hi Stuart
Is the previously attached vi in the main-loop of your main vi? Could you post both of them (please as LV7.0)?
It's quiet hard to solve your problem without the possibility to have a look at your main vi.
Thomas
09-29-2005 03:39 AM
09-29-2005 03:49 AM
Hi Stuart
Obviously you must have missed that I just use LV7.0. Could you attach it again for this version (Menu File >> Save with options >> Save for previous version)?
Thomas
09-29-2005 03:58 AM
09-29-2005 04:07 AM
Hi Stuart,
In addition to what bektho has said...
It's not clear whether the sub-vi "Read Tag.vi" is to blame. Also, the second time _this_ VI is called, the shifted-array will still be there, so if "elements subtracted" hasn't changed, then loop-abort condition will be true on first iteration. Just a note on logic, an un-initialized shift-register saves data between runs - even if you stop the VI. You may want to put some condition inside the loop that allows the data-array to be emptied. (see attached example.) The comment on the FP of your example implies that you would like to see intermediate indicator values on the FP of the caller. You can do this with control referenc(s). Your connector outputs only return the final values when the subroutine terminates. I added a reference to a DBL to the attached. On your top-level VI, create a DBL, then right-click and create reference. Wire this to the reference input I added.
You can use references to dynamically change values used in the subVI (change Property-node to Read.)
Hope it helps!
09-29-2005 04:11 AM
First of all - I'm not used to the DSC-module.
But - if the tag was read event-based, the loop should wait until data is available. So as you describe the problem, I assume that your subvi reads the values each time it is executed. I don't know if Read Tag.vi waits until a value change occurs, but I'd suggest you to check, if it realy reacts just on a value change event.
Thomas
09-29-2005 05:07 AM
09-29-2005 06:01 AM
09-29-2005 10:32 AM - edited 09-29-2005 10:32 AM
@Stuart Wilson wrote:
I am using the attached sub vi to return max, min, and average values received from a plc on our factory floor. The data in the sub vi is analysed every time the value in the plc changes rather than analysed after a set time delay.
... I am measuring "handling times" for a 5-step production sequence.
Stuart,
Are the total handling times for each step for each production sequence being logged to Citadel/DSC's database?
If yes:
Rather than using your rolling average subVI, you could write code that makes use of DSC's "Read Trace.vi".
With the appropriate start/end time selections, you'll get an array that you can cut down (if necessary) to the last 20 values to get your 'Last 20" average.
If you read the trace for the whole day/shift, you can easily get the max/min/average for the day with the ArrayMaxMin function you're currently using and Mean.vi (Functions > Math > Prob&Statistics).
Message Edited by Donald on 09-29-2005 11:33 AM