06-22-2022 08:20 AM
Hello,
I'm new to Labview and I have some problems with my general app structure:
I have a app with multiple buttons. For each button I created an "Mouse Down" event. Because I want to have the possibility to press the Buttons multiple times, every event is in its own endless while loop. First of all, this works fine. But when I want to pass data out of the while loop to other events, I have a problem. The data will not leave the loop, because the loop never ends.
Now I have two questions:
1. Is my general software concept with multiple events in single while loops correct? Or is there a better solution?
2. If my concept is right, how can I pass data to other events? I know that I can use global variables, but for some datatypes, like VISA sessions, I found no matching datatype.
I attached an example for my problem.
I hope you can help me with this...
06-22-2022 08:27 AM
Hi lvhvl,
@lvhvl wrote:
1. Is my general software concept with multiple events in single while loops correct? Or is there a better solution?
A better solution: use just one loop with an event structure. Handle all event cases in this event structure!
Your loop should never run "endless" (exept when running on a FPGA)…
06-22-2022 11:17 AM
@lvhvl wrote:
I attached an example for my problem.
No you did not.
@lvhvl wrote:
For each button I created an "Mouse Down" event. Because I want to have the possibility to press the Buttons multiple times, every event is in its own endless while loop.
This makes absolutely no sense. I assume that you want to have something happen each time you press a particular button. Put that in the Event structure. Also set your button to Latch When Released and trigger on a value change event. Be sure to put the button inside that case of the event structure. The event structure is inside a loop (not endless - you need to have a way to stop the loop via either a Stop button or a Panel Close? filter event.
@lvhvl wrote:
1. Is my general software concept with multiple events in single while loops correct? Or is there a better solution?
No
06-22-2022 11:42 AM
@johntrich1971 wrote:
@lvhvl wrote:
1. Is my general software concept with multiple events in single while loops correct? Or is there a better solution?
No
The concept is wrong? or there is no better solution? 😋
06-22-2022 12:11 PM
@Frozen wrote:
@johntrich1971 wrote:
@lvhvl wrote:
1. Is my general software concept with multiple events in single while loops correct? Or is there a better solution?
No
The concept is wrong? or there is no better solution? 😋
Basically both. There isn't really a good reason to separate the UI handling into multiple loops to handle different buttons in different loops. That makes no sense and it overly complicates the UI. The only time this would make sense would be if you were using subpanels. But in that case each subpanel is basically it's own UI. Generally speaking all of the UI should be handled in a single loop with an event structure. Otherwise you end up with the issues the OP is running into.
The UI loop should do nothing other than handle the UI events. The business logic should be it's own task. This provides a much more flexible solution and allows the code to run headless if necessary.
06-22-2022 03:09 PM
@Mark_Yedinak wrote:
@Frozen wrote:
@johntrich1971 wrote:
@lvhvl wrote:
1. Is my general software concept with multiple events in single while loops correct? Or is there a better solution?
No
The concept is wrong? or there is no better solution? 😋
Basically both. There isn't really a good reason to separate the UI handling into multiple loops to handle different buttons in different loops. That makes no sense and it overly complicates the UI. The only time this would make sense would be if you were using subpanels. But in that case each subpanel is basically it's own UI. Generally speaking all of the UI should be handled in a single loop with an event structure. Otherwise you end up with the issues the OP is running into.
The UI loop should do nothing other than handle the UI events. The business logic should be it's own task. This provides a much more flexible solution and allows the code to run headless if necessary.
Ahh... so there is a better solution. 😉
06-23-2022 12:50 AM
Hello,
thanks for that answer.
How can I implement your last sentence? I have one big while loop. Inside I have my events for every button of my UI. And where can I place the logic of my application if I should not place it inside the event? And how should I connect my UI then to the logic?
Sorry if I misunderstood your reply.
06-23-2022 01:32 AM
Hello,
I did what you wrote. But now I have the problem. That the event only gets fired the first time I press a button. If I press for example the "Import new Profile Button" a second time, nothing happens. Also the UI gets frozen, if I press a button multiple times in a short time.
06-23-2022 08:57 AM - edited 06-23-2022 08:57 AM
Sorry, I only have LV 20 so I cannot look at your code. If a button is only working once with an event structure usually means your code is not making it back to the event structure. IE put a break point in your button's event case and turn on tracing once it gets there.
06-23-2022 09:11 AM
I also don't have LV 21 installed so I cannot open your VI. However, a basic application can have a while loop that captures all of your UI events. It uses a queue to send event messages to a separate while loop that is a queued message handler or a state machine. There is a nice presentation for a true state machine framework that Norm from NI did several years ago. It was called the TLB architecture. A queued message handler would also work. The logic for that application control would go in the QMH/state machine while the UI is handled by the UI event handling loop. You can also accomplish the same thing using the actor framework. Look for presentations on the model/view/controller architecture.