04-10-2019 11:29 AM
In most cases we would want to clear a graph to start with a new data acquisition. In my case, however, I would like to retain the previous cycle's values on the graph. The point of doing this being that I would like to see the state of transition between different cycles of acquisition. In this example different cycles of acquisition is analogous to executing one VI run.
The example here clears the graph every time I run the VI. Is there a way to set it to retain the graph from the previous run and explicitly clear only when the user wants to (which can be done using a property node and a Boolean control).
Solved! Go to Solution.
04-10-2019 11:32 AM - edited 04-10-2019 11:35 AM
The data is held in a shift register, so you would need an uninitialized shift register.
(Better use a state machine. A real app should not be started and stopped, be always running, and just transition from idle to active states)
@asukumari wrote:
(which can be done using a property node and a Boolean control).
No, graphs are cleared by wiring empty data to them or in this case clearing the data in the shift register. Clearing the control is short lived if the shift register still contains the data. (Charts can be cleared by writing to the history data property, but that's a different topic)
04-10-2019 01:05 PM - edited 04-10-2019 01:33 PM
I see, therefore adding an event structure to start and stop an acquisition is the right way to do it.
Attached is an example using uninitialized shift registers. The functionality still seems to be the same, it doesn't seem to retain the values from previous event. Is this because I am not passing the data between different events in the event structure itself?
UPDATE:
Added shift regs to while loop to retain the values. Did I do it the right way? It seems to work. Is there any other caveats I should be aware of if I am building a large app which may entirely depend on state machine architecture?
Thank you for directing me in the right direction.
04-11-2019 09:39 AM
@asukumari wrote:
Attached is an example using uninitialized shift registers. The functionality still seems to be the same, it doesn't seem to retain the values from previous event. Is this because I am not passing the data between different events in the event structure itself?
But you DID INITIALIZE your shift registers. They are being initialized to empty arrays. Uninitialized would be not wiring a starting value into the shift register. Enjoy this little nugget for some clarification: Action Engine.
04-11-2019 11:11 AM
@asukumari wrote:
. Did I do it the right way?
Sigh! That "NiVerified" in the file name tells me that you scavenged that code from some posted example. In that case you should provide a link to it.
You did not attach the code version where you also use a shift register in the outer loop, but there you should decide if you want to initialize it or not. Depends if you still want to retain data between stop/run or if this is now a state machine that never stops.
In any case, that example is somewhat flawed and I don't like it at all.
04-30-2019 01:41 PM
Yes that NI Verified was an example program (I assumed it's certified by NI to be a much cleaner minimal working example than the one I wrote )
Anyway, I will re-structure and try with Producer-Consumer architecture. The last 2 points you provided in specific are really fundamental to maintain code clarity and clean UI. Thank you !