LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop issue

Hello all,

I'm having issues with a very simple While Loop issue that I'm sure is going to make me look stupid!  But I'm new to Labview and no searching or tutorial searching has helped so maybe someone here can.

I'm using labview to communicate with a piece of hardware I'm building via the USB RAW functionality.  I'm communicating fine with my USB device - which I oddly thought would be the most difficult part, go figure.  In any case, the structure I'm building is a continuous outer while loop, and inside I'm going to have a number of other while loops that I will only want to run once whenever I push a control button.  This is to send single defined commands to the USB device.  There will be about three of these in the whole VI to send different commands to the device via switches, so the final structure will have a main functioning VI in the outermost while loop, with the command whiles occasionally firing whenever the user pushes the button to send a command to the device. 

I've attached a capture of my current VI.  The rocker switch is set to latch when pressed and the inner while loop is set to Continue while True, so I would have assumed the command would only get sent whenever I push the button and it would only get sent once.  However, currently the VI just sends the command over and over again until I stop the outer loop with the stop button, regardless of what I do to the "Send Command" switch.  I've tried moving the "Send Command" switch to the outer while loop and passing the value into the other while loop (a loop "pipe" or something like that), but that doesn't seem to help.  Does anyone have any ideas?  Any help would be appreciated.
0 Kudos
Message 1 of 3
(2,642 Views)
No matter what, a while loop will always execute once. You could have a false constant wired to the loop termination terminal and it would still execute once. A while loop is totally inappropriate for a stucture in what you're trying to do. Better to replace the while loop with a case statement. Wire the Boolean that you currently have to terminate the while loop and wire it instead to the case selector. Even better than a case statement would be an event structure. Both of these are pretty basic and there are plenty of shipping examples that you can look at.
0 Kudos
Message 2 of 3
(2,638 Views)
Here's a picture of a simple case statement and an event structure.
0 Kudos
Message 3 of 3
(2,634 Views)