LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

a program structure issue?!

Dll all,
 
  I am a beginner for the Labview. I'd like to write a vi to achieve that when pressing the "OK-A" button, The LED-A begins to flash at every 1000ms in a while loop; when pressing the "OK-B" button, The LED-B begins to flash at every1000ms in another while loop, and the LED-A stops in itself loop; Repeat the above actions...  For the details, please refer to the attachment(LV7.1).
 
  Conld you help me to fix this issus? Thanks in advance.
 
  Evan-y
0 Kudos
Message 1 of 5
(3,055 Views)
Hi

In your VI, the front panel gets frozen after you click "OK-A".

Have a look at the attached VI ; it is strongly recommended to use only one event structure to manage the user interface, there are some white papers about event structure, as you are new to LabVIEW you should read them.

Also, if you want your LED to blink you don't necessarily need to keep changing its value in a while loop, you can use the "blink" property, but carefull if you do because the value will remain false 😉

hope this helps


We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

0 Kudos
Message 2 of 5
(3,039 Views)
Hi TiTou,
 
  Thanks for your help. I am interested in Labview,so I will keep on learning the Labview.
 
 
0 Kudos
Message 3 of 5
(3,025 Views)
Your program has a few very basic flaws that would be important to discuss.
  • If you don't wire a time to an event structure, the timeout is infinite, as if the timeout case does not even exist. This means that for the loop to spin once, both event structures need to fire. However, since you trap each event structure with an inner loop AND lock the front panel until the event completes, you're completely deadlocked.
  • Since your stop button does not fire events, your VI cannot be stopped until you (1) press stop AND (2) fire both other events once more (which we know cannot happen).
  • You don't define what should blink right after the program starts and you don't define if it should be possible to turn off both LEDs ever again.
  • A "press until released" boolean action coupled with a "mouse down" event seems like an odd combination. I would use "latch when released" and "value changed" instead.
  • Never put UI while loops inside event structures.
  • All you typically need is ONE while loop and ONE event structure. IF you need more than one event structure, they should each be in their own, independent loop.
  • Your 20ms timeout seems pointless.

What you need is a simple state machine with three states: (1) [both off], (2) [A blinking], (3) [B blinking], best defined as a typedef enum. Use a boolean in a shift register to do the 1000ms on/off and have a case structure that wires the desired LED to it. The event structure simply switches state depending on what was pressed and what the current state is.

Attached is a simple example with a few diagram comments. (I use a plain enum in the example for simplicity). See if it helps.

Personally, I don't really like to use the "blinking" property, because it is less flexible in terms of rate. I my code it would be trivial to change it to blink ever 300ms or every 2 seconds. Here it always blinks between the regular on/off colors and not some other color scheme.

If you get stuck with code like you did, it always helps to observe the diagram in execution highlighting mode. You will see where the "hangup" is. 🙂

Message 4 of 5
(2,990 Views)
Dear altenbach,
 
  Thanks a lot for your advice.
 
  I have a question to you for your attached vi. How can I modify your vi to do this?
 
  when I press "ok-a" button, and then the program go to run "A blinking" event, I just want to flash 10 times for the Led-a at every 1000ms; When the led-a is flashing for 10 times, if I press "ok-b" button at this time, the Led-b will start to flash 10 times at every 1000ms immediately, meanwhile the Led-a will continue to flash until finishing. Or nothing is happened after, the Led-a and Led-b are both dark after the Led-a is finished. Repeat the above action.....
 
  Could you give me some instructions for this question? Thank you again.
 
 
0 Kudos
Message 5 of 5
(2,950 Views)