05-30-2013 04:58 PM
Hi,
I am working on an issue. I have two subMainVI and both of them has have own FrontPanel. I want to merge these two subMainVI into the program and call them repeatadly with the another Main VI front panel. Simply, I when the program starts, the mainVI FP open and there are two buttons. When user clicks the button A, the subVI A FP open and it executes (some user events...) till the user close the VI (the standard cross button). Then the user can click the button A again or for a change the button B and then the subVI B starts to execute (event again). The program should run till the main VI (with the two buttons) is closed.
I tried to do something similar with one subVI, but I was not succesfull. I was able to open and close the subVI once, but then the app gets frozen...
I do not have much experience with events...I believe it may be easy for someone...I would appreciate some simple code example...
05-31-2013 06:09 AM
The easiest way to do this is using a Queued Message Handler. Use the event structure to catch the button press, and then do the processing in a different loop with a case structure.
I have attached a simple template to get you started.
05-31-2013 08:50 AM
Here's an easy way to do it, using a WHILE loop, T/F Case structures and local variables.
Cameron
05-31-2013 09:05 AM
First of all, you really need to Unregister your events. It works just fine then.
Secondly, you don't need to register for the panel close. It is in the event list already.
Give this mod a try.
05-31-2013 09:07 AM
@camerond wrote:
Here's an easy way to do it, using a WHILE loop, T/F Case structures and local variables.
Cameron
It may be an easy way to do it, but it's basically bad programming. You shouldn't use while loops to poll buttons when you can make it event-driven.
05-31-2013 09:20 AM
@billko wrote:
@camerond wrote:
Here's an easy way to do it, using a WHILE loop, T/F Case structures and local variables.
Cameron
It may be an easy way to do it, but it's basically bad programming. You shouldn't use while loops to poll buttons when you can make it event-driven.
But if he's confused with events, this does work. It may not be the most elegant solution, but that doesn't make it "bad" programming unless it interferes with his tasks. Computers are so fast and have so much memory now, that you don't always have to do things the most efficient way to get them done. Just IMHO, it's better to help someone with something he can understand than to give him a black box with magic inside, unless his goal is to learn the magic now.
TIMTOWTDI.
Cameron
05-31-2013 09:23 AM - edited 05-31-2013 09:25 AM
@camerond wrote:
@billko wrote:
@camerond wrote:
Here's an easy way to do it, using a WHILE loop, T/F Case structures and local variables.
Cameron
It may be an easy way to do it, but it's basically bad programming. You shouldn't use while loops to poll buttons when you can make it event-driven.
But if he's confused with events, this does work. It may not be the most elegant solution, but that doesn't make it "bad" programming unless it interferes with his tasks. Computers are so fast and have so much memory now, that you don't always have to do things the most efficient way to get them done. Just IMHO, it's better to help someone with something he can understand than to give him a black box with magic inside, unless his goal is to learn the magic now.
TIMTOWTDI.
Cameron
Understood, but teaching someone bad habits is not good, either. Best to learn the right way or it will cause problems down the line.
[edit]
Granted that a QMH might be too complicated for a beginner, but then a simple event-driven structure would've been a better choice.
05-31-2013 09:32 AM
@billko wrote:
@camerond wrote:
@billko wrote:
@camerond wrote:
Here's an easy way to do it, using a WHILE loop, T/F Case structures and local variables.
Cameron
It may be an easy way to do it, but it's basically bad programming. You shouldn't use while loops to poll buttons when you can make it event-driven.
But if he's confused with events, this does work. It may not be the most elegant solution, but that doesn't make it "bad" programming unless it interferes with his tasks. Computers are so fast and have so much memory now, that you don't always have to do things the most efficient way to get them done. Just IMHO, it's better to help someone with something he can understand than to give him a black box with magic inside, unless his goal is to learn the magic now.
TIMTOWTDI.
Cameron
Understood, but teaching someone bad habits is not good, either. Best to learn the right way or it will cause problems down the line.
[edit]
Granted that a QMH might be too complicated for a beginner, but then a simple event-driven structure would've been a better choice.
It's never a good idea to peg a CPU core to just poll a button. Instead, we should be trying to help the OP understand the event structure. I looks like they already understand it enough to use dynamic events.
They're only problem was not unregistering the events. If you don't unregister, then the next registration will likely not work, which is what happened here. But the easier solution is to just not use the dynamic events since the VI Panel Close event is a default one that you do not need to register for.
05-31-2013 09:37 AM
@camerond wrote:
Here's an easy way to do it, using a WHILE loop, T/F Case structures and local variables.
Cameron
Ok, just looked at your example. Event structure is so much easier. And to make it even easier on you, use latching buttons. Then you don't need the locals to reset the buttons. When the button's terminal is read, the latch will reset. And I don't see where this is applicable to the OP's question about the subVI's panel not closing
05-31-2013 09:39 AM
Wait, wait 250 msec now. I didn't peg the CPU core, I had a quarter-second wait in there between loops. At least I did that right, AFAIK. Didn't I?
You may have realized that I'm not a real computer jock by now. The last 18 years or so I've been doing most of my programming in Perl, where TIMTOWTDI is a way of life.
Cameron