05-16-2017 01:16 PM
Does anybody knows how can we clear na array that is included in a non stop while loop?
I attached na exemple that I would love to reiniciate the array for the secon part of sequence.
Thanks in advance
Solved! Go to Solution.
05-16-2017 04:46 PM
First piece of advice -- never use a Stacked Frame. While they still exist, NI removed them from the Block Diagram Structures Palette in LabVIEW 2014.
You can achieve equivalent (but much better) functionality by replacing the Stacked Sequence with a Case Statement. Wire the Index of the surrounding Loop to the "?" input of the Case, and make the 0 Case the Default (to clear the Error). Keep your Array in a Shift Register, then if you want to "clear" it in Step 5, simply replace the Array with an empty Array.
Bob Schor
05-16-2017 05:21 PM
@Bob_Schor wrote:
First piece of advice -- never use a Stacked Frame. While they still exist, NI removed them from the Block Diagram Structures Palette in LabVIEW 2014.
You can achieve equivalent (but much better) functionality by replacing the Stacked Sequence with a Case Statement. Wire the Index of the surrounding Loop to the "?" input of the Case, and make the 0 Case the Default (to clear the Error). Keep your Array in a Shift Register, then if you want to "clear" it in Step 5, simply replace the Array with an empty Array.
Bob Schor
This type of structure:
is worse than this:
05-16-2017 05:25 PM
@paul_cardinale wrote:
This type of structure:
is worse than this:
Depends entirely on what you're working on. The sequence is better if you're dead certain on the ordering of the frames. The loop is nice when you're unsure... instead of wiring with the [i] terminal, you can use an array constant to re-order. I've done that many times when trying to configure an unknown API or when relevant user requirements keep changing.
Most of the time, though, I'd use a sequence structure for this kind of scenario.
But I'd prefer a flat sequence over both. And I'd prefer no sequence most of all! 🙂
05-16-2017 05:32 PM
Paulo:
I looked at your VI. I am not sure what you are trying to test. This is very unusual G code. I think I can answer your question, but I've got to clean up the code. For example, you have a nasty race condition -- you have an empty array written to the FPTerminals... that can happen at any time, even in the middle of your test. In practice, it happens at the beginning most of the time, but there's no guarantee of that behavior because parallel code makes no such promises. I'll try to post some pictures in a few minutes.
05-16-2017 05:48 PM
This both answers your question and, I hope, shows you a couple of better techniques for your G code. The "Start test" Boolean shown below is now a regular button on the panel, so it has proper reset behavior when read. The event structure means you don't have to sit there and poll the Boolean. Even if you're programmatically triggering this, the event structure is a better choice for performance because it eliminates polling.
I haven't changed the core of your test. I don't know enough about what you're testing. I will say that all of this work with local variables makes me *really* nervous. Those are my tools of last resort, so I only employ them if there is absolutely nothing else that will work. Be careful with them... it is easy to kill the performance of LabVIEW and/or get yourself into some nasty race conditions by using local variables too much.
05-17-2017 03:31 PM
I understood but in this case i can't use shift register.
Just to carify, one loop is used to control some features of the second one. The attached vi os just a small part with the question that I would like to solve but the program is quite bigger. It has some non stop loops that works the parallel to collect information fro diferente machines. However what I need is using an array calculate an average and get that actions evry time that I need but always that I use the array I can't clear for the next cicles.
05-17-2017 03:54 PM - edited 05-17-2017 03:55 PM
I'm going to jump in and say what should already have been said.
Stop using infinite loops. The architecture you describe is an "Actor" aka "Queued State Machine" or QMH.
The methods that those "Actors" implement may be things like these :
:
Or something like that. Read "A Trip to Grandmas house"
Finally, stop using the abort button to halt your vis
05-17-2017 04:13 PM
@JÞB wrote:
I'm going to jump in and say what should already have been said.
Jeff: I wanted to say many of those things, but this is a customer I have not worked with before, so I'm ooching into architectural changes slowly. Everything that you list would likely help this user in the long run, but I don't know where they are in the design process... this is one of those questions that sounds like "help... I'm stuck and need short term help", so I try to provide a short-term help answer. 🙂
Paulo: Was my post helpful? There aren't any shift registers in the picture I posted. (I'm not sure *why* you cannot use a shift register in this case, but I'm willing to go along with that for the moment.) When you have more time, you really should read Jeff Bohrer's post... he is correct that the design you're using has a number of problems that we generally try to avoid in good LabVIEW code.
05-17-2017 04:15 PM
The first loop is always running to collect data from a device. I'm simulating that using a random number generator. The second loop is also a simulation also that I made just to explain my doubt. The sequence is to gathering some data from the first loop during a while. All collected data is storage into an array. After that I need to stop collecting data to the array because i need to make some calculations with that colected data. This part is not simulated here but is not relevant to this issue. I just use a waiting time to simulate that Im make something during that time. Finally I need to restar to collect data again but I must to clean the array before however after the ceanimg action when I try to store new values I got all data history again.