LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

building disabled items array

Hello,

 

I'm trying to build a vi that reads in boolean true/false values, then correspondingly disables the false ones on a ring.  The problem I'm having is that I can't build the array for the disabled items indices correctly.  I've looked over the attached file several times and tried to do some error checking, etc. (which explains some parts of the vi), but I can't figure out why it isn't working correctly.  Any help on the matter would be much appreciated.

 

Scott

0 Kudos
Message 1 of 7
(3,136 Views)

The problem in your VI is the loop condition.  Your condition states that the loop should stop if the size of the array is greater than the current index.  Since the current index ('i') starts at 0, your 16 element array of booleans will always be greater than it. 

 

You can either change your loop condition terminal to a loop on true, or change your comparison statement.

0 Kudos
Message 2 of 7
(3,133 Views)

OK, first you should learn some basics, because your code is very bad.

 

  • Since you know the number of iterations, you need a FOR loop. No need to test for termination conditions.
  • Your VI is full of race conditions due to misuse of local variables. Always read from the terminal. For example, you have "Enabled channels 1,0" disconnected and create two instances of a local variable right next to each other inside. Why? Do you think there is a chance they they give different results at different iterations? Most likely, the values are static for the duration of the loop, so the data source belongs outside the loop. Don't be afraid to branch a wire!

 

Here's a quick draft for some of your code snippets. See if they make sense. (... and don't use the "continuous run" button!)

Message Edited by altenbach on 04-06-2009 09:43 AM
0 Kudos
Message 3 of 7
(3,119 Views)

Your real problem is that you're trying to write LabVIEW code as if it were VB code. LabVIEW code does not execute top to bottom or left to right. You are using local variables where you should be using wires. LabVIEW is a dataflow language, not a linear/procedural language. Thus, you cannot write code in the same way as you with text-based languages. None of your local variables are necessary. Plus, since you have three independent loops, there is no control as to which one executes first because you are using local variables. This is a classic race condition.

 

Also, your use of the uninitialized shift register will cause problems as with subsequent runs it will use the contents of the shift register from the previous run. 

 

As to the premise, an easier solution would be to use a cluster of Booleans rather than individual Booleans. You also only need one loop, not three. 

0 Kudos
Message 4 of 7
(3,117 Views)

(duplicate due to site issues. Ignore)

Message Edited by altenbach on 04-06-2009 09:42 AM
0 Kudos
Message 5 of 7
(3,116 Views)

Thanks for the input.  The posted code is a good starting point for further discussion.  First, how did you make the array of push buttons?  Second, if you have a loop, does the next event "down the wire" wait until the loop executes?  I presume it does... 

 

Thank you,
Scott

0 Kudos
Message 6 of 7
(3,092 Views)

SAMullin wrote:

First, how did you make the array of push buttons? 


 

Drop an array container on the front panel, drop the button in it, resize the container, click on the last element to define the array size, make current values default. save VI.


SAMullin wrote:

Second, if you have a loop, does the next event "down the wire" wait until the loop executes?  I presume it does... 


Yes. It's called dataflow. A structure cannot execute until it recevied data on all inputs and a structure only outputs data when all of it has finished. Everything wired to the output of a loop for example will wait until the loop has completed. Isn't it great! 😄

Message Edited by altenbach on 04-06-2009 10:36 AM
0 Kudos
Message 7 of 7
(3,085 Views)