LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Clearing Variables at end of a loop

Hi All,

 

So I am new to labView, but have gone through all the tutorials and looked through the forum first. I am having trouble understanding how to clear out my arrays (effectively delete them) at the end of my main loop so they can be rebuilt on the next run of the main loop. 

 

My program reads in a user-defined amount of samples from two DMMs using VISA communications over COM ports. What I want it to do is after finishing a run, delete and clean up its data so that on the next run the arrays that will be created start from index 0. I know how I would do this through writing code, but I am having some trouble understanding how labView manages variable resources. I attached the VI below. I know I have some other things to clean up, so if we could just focus on the two main arrays that come out of the VISA messaging that would help the most.

0 Kudos
Message 1 of 11
(5,936 Views)

updated vi with some cleanup to fix COM port issues. 

 

any thoughts on how to initialize or delete the arrays at the beginning/end of a loop run?

0 Kudos
Message 2 of 11
(5,842 Views)

Don't have/use NXG, so can't look at your code (but thanks for attaching code).  However, the way to "clear" an array is to simply wire an empty array.  So if you have a While Loop and bring out an array wire with lots of data, break the wire and at the now-broken right (assuming your wires run left-to-right) end of the broken wire, click and create an Array (which, by default, will be blank, thereby "clearing" the data on the wire).

 

Bob Schor

 

P.S. -- usually you initialize (clear) Variables at the beginning of a loop.  At the end of the loop, you either "use them or lose them", i.e. you either want the data on the wire and therefore take it someplace and use the data, or you don't need it anymore, and simply don't carry the wire forward (i.e. "lose" it).

 

0 Kudos
Message 3 of 11
(5,719 Views)

Perhaps you can also post an image.

 

NGX isn't used that much yet.

0 Kudos
Message 4 of 11
(5,718 Views)

Hi LucasM292,

 

I second Bob's idea of starting with an empty array before running the loop to read your data. You can right click on your array shift register and create an empty array constant. From there, you could use Build Array to add new readings to the array (after you format the string from VISA Read).For reference:

 

Clear array.png

 

Thanks,

Frank

0 Kudos
Message 5 of 11
(5,653 Views)

I think you just need to wire an empty constant into your feedback nodes. You could also use the shift register instead of the feedback nodes. You will need to initialize them to empty arrays as well. I believe either of these two options would work for you. When you have an uninitialized shift register or feedback node, the VI will use the value it has saved from it's last execution. If you want to always start at "zero" you need to initialize them to the value you want to start at. 

 

https://zone.ni.com/reference/en-XX/help/371361R-01/lvhowto/initializing_shift_registe/

 

shift register 2.png

Regards,

Jon S.
National Instruments
LabVIEW NXG Product Owner
0 Kudos
Message 6 of 11
(5,648 Views)

Thanks Everyone!

 

Unfortunately wiring an empty array to the init of the feedback node did not work. Also tried wiring an empty array in through the shift register; that didn't work either.

 

I tried making a new button and a new case so that when that button is pressed 0 size arrays get loaded into the outputs. unfotrunately that just replaces the output, but does not delete the data stored in those arrays. 

 

any other ideas?

0 Kudos
Message 7 of 11
(5,624 Views)

Oh, dear.  Not only is this in NXG, but it is in NXG 4.0, the Absolutely Latest Version (which I have not yet installed on a VM:) ... (and that's not supposed to be a Smiley or Frowny or Anything else Face just before the ellipsis).  Guess I'll have to try to upgrade ...

 

Bob Schor

0 Kudos
Message 8 of 11
(5,429 Views)

Hi Everyone, any other thoughts on this? I did some searching and trying over the past two weeks but nothing seems able to clear out these arrays except closing and re-opening the program.

0 Kudos
Message 9 of 11
(4,298 Views)

I am a little confused on what exact value you are trying to "reset". Can you show us the exact wire on the diagram? If you are referring to resetting one of the front panel controls back to "zero" when you start a program. You can use a duplicate terminal to set those values to zero when you start an application.

 

For example, if you are trying to reset the "DC V" and "DC V 2" back to empty arrays when the program starts, Create a duplicate terminal and write an empty array of values to that duplicate terminal before the event loop starts.

Regards,

Jon S.
National Instruments
LabVIEW NXG Product Owner
0 Kudos
Message 10 of 11
(4,282 Views)