LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Keep program running

Solved!
Go to solution

Hello, i'd first like to apologize for this very beginner-like question... Im very new to labview and i'm starting to see the potential and liking it, but i'm having troubles so far.

 

I have this piece of hardware that i'd like to control with LabVIEW and the pieces of code i've constructed works, but the program terminates when i've pressed both of my buttons? 

 

I have two event sctructures that react when mouse is down on two different buttons, the blocks inside the eventstructure is executed as they should etc.

 

The problem is that when i've pressed both my buttons, the program terminates. I'd like to add more code to be done afterwards. And it seems i'm not able to run the same event structures twice? I can't push the button again, it goes dark and stays dark. (After i press it first time it switches back, it is after i press 2nd time it stays dark). 

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

Well, obviously it is not programmed right, so we probably need to see the code.

 

(Why do you have two event structures? Typically one is sufficient. What is you code architecture? Do you even have a toplevel while loop?)

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

Here is the program, i tried to do top level while-loop but i'm sure it worked as intended. The two white blocks are working as they should and are outputting what they're supposed to. Capture.PNG

0 Kudos
Message 3 of 7
(3,928 Views)
Solution
Accepted by topic author Blofeld

You have misconception about event structures. Please refer to tutorials/help and examples for event based implementation. They should help you in understanding your misconception. I recommend specifically reading about event structure pitfalls.

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 4 of 7
(3,923 Views)

Okay, i'll look into that. Given the simplicity of my problem i'll mark this as a solution for now. 

0 Kudos
Message 5 of 7
(3,919 Views)

The event structures are not the primary problem, it is your complete lack of understanding of dataflow,, that can easily be solved by doing some basic LabVIEW tutorials.

 

What is happening in your case:

  • The program runs and both event structures wait to be fired.
  • At the same time, that lone disconnected library node on the bottom right runs too. No sure what it's purpose is. (execution order is determined by dataflow, not xy placement on the diagram!)
  • Once the upper button is pressed, the code in the upper event executes and the event structure completes, never to run again in that same session
  • Same for the lower button.
    • NOTE: If you would press the lower button first, nothing would happen because that event structure has a data dependency from the upper event. This means that the event cannot act and goes onto a queue and will fire immediately after dataflow allows, i.e. right after the upper event has also fired and completed.
  • Once both events have executed, no code remains and LabVIEW stops.

What needs to be done:

  • Use a toplevel while loop
  • Place all code that needs to execute on initialization before the loop and create a data dependency such that it must execute first.
  • Use a single event structure with two cases, one for each button (You possibly can also combine them into one event using a case structure inside it)
  • Make the events "value changed" for the buttons and place the button terminals inside their respective event cases so they reset when the event fires (Assuming they are latch action). ("Mouse down" events should be rare. They are meant for other things, e.g. mouse down on an indicator, etc.).
  • Keep some state data in a shift register, e.g. if the second event is only allowed to do something useful once a spectrometer is connected.
  • Also create a stop button (and event for it) to end the program, possibly triggering some cleanup code. You can also use a discarded filtering event for the [X] in the upper right corner to stop the VI.

See how far you get... 😉

Message 7 of 7
(3,865 Views)