12-19-2019 11:55 AM
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.
12-19-2019 03:43 PM
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?
12-20-2019 03:46 AM
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).
12-20-2019 03:47 AM
12-20-2019 10:29 AM
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:
Thanks,
Frank
12-20-2019 10:47 AM
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/
12-20-2019 12:21 PM
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?
12-21-2019 08:48 AM
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
01-06-2020 11:51 AM
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.
01-06-2020 12:47 PM
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.