LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Returned after many years, feeling v stupid!

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 🙂

0 Kudos
Message 1 of 10
(2,605 Views)

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.

Message Edited by altenbach on 10-02-2008 11:37 AM
Message 2 of 10
(2,601 Views)

A few more comments:

 

  • The file io wants DBL, so first converting to integer and then back is a waste of resources.
  • The numeric indicator is quite useless, because the loop runs so fast that you'll only see the last value anyway. You migh as well place the indicator after the loop in order not to bother the program with front panel updates.
  • It seems you simply want to round to whole numbers (0...1000), there is a tool for that.

 

Here's an example of equivalent code that's a bit easier to maintain. 🙂

 

Message Edited by altenbach on 10-02-2008 11:36 AM
Message 3 of 10
(2,593 Views)
Sorry about the breakpoint, my bad. It's there to stop the file write. I tried a for loop after the While to step thru the array, and it still came out empty. Each update to the array seems to clear out the previous contents, it writes to array[4] and array[3] is cleared. Why? Thx for your rapid reply, but my aim is to understand array operations, not write random numbers to files!
Message Edited by NoVIsonme on 10-02-2008 01:45 PM
0 Kudos
Message 4 of 10
(2,588 Views)

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.

 

Message Edited by altenbach on 10-02-2008 11:50 AM
Message 5 of 10
(2,580 Views)

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.

Message 6 of 10
(2,574 Views)

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.

0 Kudos
Message 7 of 10
(2,573 Views)

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.

Message 8 of 10
(2,565 Views)

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?

 

 

What's the triangle for?

0 Kudos
Message 9 of 10
(2,551 Views)

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). 🙂

Message 10 of 10
(2,508 Views)