LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help needed on building arrays.

Someone, please help.

Hello again!

About this data acquisition and array thing again. I still couldn't make it work. Here's what I did.

1) I created 2 While Loops side by side (not inside eachother)
2) Then put the data source in the first While Loop (this is a main program, that has to run all the time) This Loop also has a graph (connected to the data source) that displays the data and (Boolean) switch and that's it for this loop.
3) Then I created a Local Variable out of this data source, placed it into the second While Loop and surrounded it with a Case Structure.
4) Then I placed the array indicator outside the second While Loop and wired it to the Local Variable (autoindexing enabled). Created also a Boolean for the Case Structure and a Boolean to control the second Loop.

Now, here's what happened next: I started the program, the graph started to display data. When I pressed the button that had to tell to the second While Loop that it was time to start passing data over to the array, the very moment I pressed this button the array filled up with the values that were stored in the "border" of the second While Loop. So it took the values that were already collected to the Loop when I started the program in the first place. So, pressing the button stoped data gathering, instead, it should have started it.
After I had this first array of values, I tried to get some new values to the array but nothing happened anymore. First While Loop was running but the second one was "frozen" again.
When I tried it with this test mode (the mode where the data flow is represented by dots ) I saw that when I first started the program, both Loops were running and the state of the Boolean switches was checked after each iteration. When I pressed the array control button, second Loop stoped and data was passed over to the array. But when I tried to get new values to the array this second Loop was still stoped although the first Loop (main program) was running. The program checked the state ot the button that controlled the work of the first Loop after every iteration but it didn't check the state of the two buttons that were controlling the work of the second Loop anymore. So the first one ran and the second one did not.

Thank you in advance,

Jared, if you hear me, maybe you can me once more.

E-mail:rihopuusemp@yahoo.com
0 Kudos
Message 1 of 3
(2,974 Views)
Look at the vi attached. Here you have two loops simultaneously executing: the main loop (here a simple led flashing) and the acquisition loop.
Inside each loop there is a 'wait for next ms multiple' to leave time for the other loop to execute.
When you push the 'acquire' button a simple VI (a tutorial vi that generate some data) is executed and data gathered in a strip chart. At the end of data collection I put data in an array (replacing old datas).
Maybe this can be a starting workaround for your problem.
The VI is fo LV 6. Let me know if you need it in LV5 format.
Hope this helps
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(2,974 Views)
Riho,

Hello again. First, when you put the array indicator outside the second loop and use the edge of the loop to gather the data into an array (using the loop autoindex) you will not see the data in the array until you stop the while loop. What is happening is : you press the boolean button to allow the local variable to output its value to the loop edge. This continues to happen for each iteratio of the loop while the button is pressed. As this is happening though, you do not see the info in the array. Why? Because the array is outside the loop. The data is collected at the edge of the loop and automatically stored in an array (the autoindex array of the loop) but nothing gets passed out of the loop until the loop stops. When the loop stops all the acquired data gets passed out to the array. The problem with this method is you press the button, data is acquired, but you dont know what data is acquired because you cant see it until the loop is stopped. Once the loop is stopped, it cannot start again until you stop and re-start the whole program. you need to have the array inside the loop so you can see what you are acquiring.

Second, now that you have the array inside the loop so that you can see what is being acquired, you have a new problem. Your data source is a single element and your display is an array. The two cannot be wired directly together. You need a 'build array' or 'replace array element' sub-vi in between your single element and your array. For now, to keep it simple, we will use the 'build array' function. it is wasteful in its memory allocation practices but i don't think right now you know the max size of your array and initializing and resizing arrays is another discussion. Lets first get through this problem.

Ok, i've attached a new sub-vi. This is how it works. One while loop, not two, but you could use the local variable method if you feel you need to seperate the two procedures again. The data source outputs to the chart and is branched off to a case structure. The case is controlled by a boolean switch to start data gathering into the array. The true case holds a build array function using the single element from the data source and an array. the output (of both cases) goes to the array indicator and a shift register on the edge of the while loop. Not familiar with shift registers? You should look into them, they are very helpful inside loops. The reason for the shift register is that earlier in this paragraph i stated the build array function had two inputs, one of them being an array. This is the array you are viewing and appending each new value onto. When you append a value and display it in one iteration of the loop, you need to pass this array into the next iteration so you can append a new value onto it. This is what the shift register does. In the false case, the array from the shift register is just passed through to the display without appending anything.

Hope this helps,

Jared

Posted and emailed
0 Kudos
Message 3 of 3
(2,974 Views)