LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multibutton App

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...

0 Kudos
Message 1 of 17
(1,359 Views)

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)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 17
(1,353 Views)

@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


 

0 Kudos
Message 3 of 17
(1,314 Views)

@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? 😋

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
0 Kudos
Message 4 of 17
(1,306 Views)

@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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 5 of 17
(1,299 Views)

@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. 😉

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
0 Kudos
Message 6 of 17
(1,281 Views)

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.

0 Kudos
Message 7 of 17
(1,262 Views)

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.

 

 

0 Kudos
Message 8 of 17
(1,255 Views)

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.


 

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
0 Kudos
Message 9 of 17
(1,234 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 10 of 17
(1,226 Views)