10-02-2008 01:24 PM
Hi guys. Been away a very long time, and it seems I've forgotten what little I ever knew about LabView 😞
All I've done is set myself a little exercise to write an array to a txt file. See attached. Should be self-explanatory. The fact that it doesn't work shows that I'm under some misapprehension about the fundamental operation of the program, prob down to array addressing, loop functions or tunnels. Can some one please put me out of my misery? Sorry again to be such a newbie, but at least you've had a laugh 🙂
10-02-2008 01:28 PM - edited 10-02-2008 01:37 PM
First, you have a breakpoint around your file IO, this means the program will pause once it reaches that point. Use the breakpoint tool and click until the red outline disappears.
Since you know the number of iterations before the loop starts, use a FOR loop. You can use autoindexing to get rid of most of the current code.
10-02-2008 01:36 PM - edited 10-02-2008 01:36 PM
A few more comments:
Here's an example of equivalent code that's a bit easier to maintain. 🙂
10-02-2008 01:37 PM - edited 10-02-2008 01:45 PM
10-02-2008 01:48 PM - edited 10-02-2008 01:50 PM
You always replace data from the fresh (empty) array from the loop input tunnel.
You need to use a shift register to operate on the array as modified from the previous iteration.
10-02-2008 01:53 PM
You are also spinning the loop one too many times.
You are trying to replace elements 0..6 (7 elements!) in an array of 6 elements, so you are wasting the last iteration.
10-02-2008 01:56 PM
Now we're getting somewhere thanks. So the array that I initialise at the start isn't passed thru the tunnel as a single object then? I thought that the file write would write the whole thing as the loop ended, not nibble by nibble. I come from a CVI background, this way is very confusing to me, tho I assume second nature to everyone else here.
10-02-2008 02:12 PM
NoVIsonme wrote:Now we're getting somewhere thanks. So the array that I initialise at the start isn't passed thru the tunnel as a single object then? I thought that the file write would write the whole thing as the loop ended, not nibble by nibble. I come from a CVI background, this way is very confusing to me, tho I assume second nature to everyone else here.
The entire array is passed to the input tunnel. Here you take it, and replace one of the elements and place the modified array into the output tunnel. At the next iteration, you again read the initialized array with all zeroes, and now replace the second element. And so on. In iteration 6, you take again the zeroed array, and try to replace the seventh element, so nothing happens and the array with all 6 zeroes goes to the output tunnel. Now the loop finishes and the file IO occurs.
There is no relation between your input tunnel and your output tunnel.
OTOH, a pair of shift registers refers to one single memory location that you initialize, then modify at each iteration, and read out once the loop finishes..
A great tool is execution highlighting to see how things work.
10-02-2008 02:46 PM
altenbach wrote:
.....
A great tool is execution highlighting to see how things work.
I'd slow it down if I could, rather that keeping a quivering trigger finger over the pause button 🙂
So the While loop is equivalent to my do.. while() loop. I get it now. The arrays auto-increment even if directly indexed? Not so happy about that. And the red triangle?
10-02-2008 11:07 PM
NoVIsonme wrote:The arrays auto-increment even if directly indexed? Not so happy about that. And the red triangle?
Nothing "auto-increments" (I am not even sure what you mean by that statement). You are using the loop index terminal as a source, and that one better increments with each loop operation. Nothing wrong with that. 🙂
If you autoindex at the loop boundary as in my example, you get an array. One element per iteration of the loop. Very convenient.
The red triangle tell you that you are not using the correct datatype for the function and that LabVIEW will coerce it. The function wants and array of I64, DBL, or string. (Many years ago it only accepted SGL, so this is probably new to you). 🙂