From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Clear arrays into a non stop while loop

Solved!
Go to solution

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 

0 Kudos
Message 1 of 16
(6,621 Views)

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

0 Kudos
Message 2 of 16
(6,597 Views)

@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:

fc.png is worse than this:ss.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 3 of 16
(6,586 Views)

@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! 🙂

0 Kudos
Message 4 of 16
(6,581 Views)

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.

0 Kudos
Message 5 of 16
(6,579 Views)

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 buttonButton 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.

 

Code

0 Kudos
Message 6 of 16
(6,576 Views)

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.

0 Kudos
Message 7 of 16
(6,526 Views)

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 :

:

  • Init
  • Clear
  • Wait (But keep listening for high priority messages)
  • Start
  • Idle
  • Close

Or something like that.  Read "A Trip to Grandmas house

 

Finally, stop using the abort button to halt your vis


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 16
(6,518 Views)

@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.

Message 9 of 16
(6,509 Views)

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. 

0 Kudos
Message 10 of 16
(6,507 Views)