LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

user interface, buttons and menus

Hi, I'm working on a user interface over my christmas break. In summary,
menus are easy but buttons are not so I'm a bit confused.

I envision a good high performance user interface as threaded using
signalling. With menus, it is very obvious how to program a good interface.
Typically I would want to get a command from the user, then fork() to
execute that command. The read-menu VIs block until a choice is made, making
this a very convenient model.

Unfortunately front-panel buttons seem to be much different! It is very
possible to use a while-loop, some conditionals, and a sleep but this is
busy waiting and this is horribly inefficient for a user interface. Even if
read-menu busy waits internally, its still a pain in the butt that fron
t
panel controls can't easily signal-when-true. I have tried wrapping each in
a while-loop: while control is unasserted, sleep and loop. Its seems very
very very inefficient and feels unresponsive, but its the best I've thought
of so far.

Is it possible to make the front panel controls more thread-like so user
interfaces can run more efficiently? Somewhat a vague question, but I really
have no clue what labview provides to eliminate the busy-waiting situation
described above.

-joey
0 Kudos
Message 1 of 8
(3,571 Views)
Hmmm,
I'm not sure I entirely understand what you are asking, but from the sounds of it you are used to event driven programming.

Typically in LabView, if you have a set of buttons on a panel you wrap all of them into one while loop, the build them into an array, then search the array to find the first button pressed. You then use a "Wait until next mS Multiple" timer to specify how responsive you wish it to be (i.e. how many times you want it to look for a change in the conditions). When a button has gone true under the above circumstance, a number will be returned, and you can then use that number to "fork" the code in a case.

I can't explain this fully (I'd be here all day), but you might want to have a look at the Resource Library for a good example of th
is:

http://zone.ni.com/devzone/devzone.nsf/webcategories/8DA27C34C5069CB486256793006F5079?opendocument&node=DZ52060_US

Hope that is of some help.
Jonathan
0 Kudos
Message 2 of 8
(3,571 Views)
"JonM" wrote in message
news:5065000000050000001D550000-1007855737000@exchange.ni.com...
> Hmmm,
> I'm not sure I entirely understand what you are asking, but from
> the sounds of it you are used to event driven programming.

Yes, event driven is exactly what I want! Thanks, that was the phrase I was
floundering for.

> Typically in LabView, if you have a set of buttons on a panel you wrap
> all of them into one while loop, the build them into an array, then
> search the array to find the first button pressed. You then use a
> "Wait until next mS Multiple" timer to specify how responsive you wish
> it to be (i.e. how many times you want it to look for a change in the
> conditions).

eek! that seems so horribly inefficient though.

T
hat's what I have right now. The trouble is that's "busy waiting" because
it sucks down CPU time in the while-loop while the condition is not true. I
understand the wait until next MS multiple (aka sleep?) will help somewhat,
but it seems like there ought to be a way for buttons to signal when they've
been pressed to prevent the program from spinning on idle.

Maybe there's no way... just seems like there ought to be! For an example of
when busy-waiting doesn't work very well at all: all the front-panel
controls latch easily except mouseclicks on images. It's fine to service a
control "when you get to it" because of busy waiting but image mouseclicks
won't latch as far as I've seen so ideally that would act more event driven
so it would reliably catch mouseclicks. Just a dumb example, but wanted to
put it forth since most people have told me to live with busy waiting so
far.

-joey
0 Kudos
Message 4 of 8
(3,571 Views)
> eek! that seems so horribly inefficient though.


If you do not place the delay, then the loop will run millions of times
per second, and you are correct, that would be a very bad usage of CPU
since the typical user can't press the button more than a few times per
second. Putting in even a 10ms delay means the buttons are checked a
hundred times per second, which is still more than necessary, but it is
about 0.01% of the resources used before. With and without the delay,
bring up the resource monitor and you will see the difference it makes
there as well.

So what may seem really expensive, polling buttons on a panel takes
hundreds of nano or small number of micro-seconds. Cheap. Whereas
drawing a button when clicked, which migh
t seem cheap, takes about a
millisecond, being about one thousand times more expensive.

Anyway, the more important thing to get out of this is to make quick VIs
to try out an implementation and use tools like the Performance Monitor,
task manager, or the LV profiler to measure the time that it actually takes.

Greg McKaskle
0 Kudos
Message 6 of 8
(3,571 Views)
"Greg McKaskle" wrote in message
news:3C22A69B.50108@austin.rr.com...
> > eek! that seems so horribly inefficient though.
>
> If you do not place the delay, then the loop will run millions of times
> per second, and you are correct, that would be a very bad usage of CPU
> since the typical user can't press the button more than a few times per
> second.

Indeed, I completely agree that the sleep() will help. I just got out of an
operating systems class this semester, so I'm probably hypersensitive to
busy-waits and threading right now. Maybe my best choice is to hack up a
solution, move on, and fix the performance issues in the next version.

My previous example of checking LV6 images for mouseclicks is again
a
fitting example because LV-profiler said it's a very expensive operation
timewise. As you describe, the impact can be very low. However with
expensive reads, lots of reads, and tons of threads sucking down
processor-time then the whole mess becomes non-negligible. Even 1/4 to 1/2
of a second for the loop is a lifetime since users get frustrated if there
is no visual response within about 1.5 or 2 seconds of clicking on anything.

It indeed sucks to be working on a fancy multi-threaded labview program and
then get tripped up by the controls, but maybe LV just can't do such a
thing... One can always hope that NI pays attention to the newsgroup and
will add it in LV7 though! Thanks for your comments. If you can think of
anything else helpful definately let me know.

-joey
0 Kudos
Message 7 of 8
(3,571 Views)
> Indeed, I completely agree that the sleep() will help. I just got out of an
> operating systems class this semester, so I'm probably hypersensitive to
> busy-waits and threading right now. Maybe my best choice is to hack up a
> solution, move on, and fix the performance issues in the next version.
>
> My previous example of checking LV6 images for mouseclicks is again a
> fitting example because LV-profiler said it's a very expensive operation
> timewise. As you describe, the impact can be very low. However with
> expensive reads, lots of reads, and tons of threads sucking down
> processor-time then the whole mess becomes non-negligible. Even 1/4 to 1/2
> of a second for the loop is a lifetime since users get frustrated if there
> is no visual response within about 1.5 or 2 seconds of clicking on anything.
>
> It indeed sucks to be working on a fancy multi-threaded labview program and
> then get tripped up by the controls, but maybe LV just can't do such a
> thing... One can always hope that NI pays attention to the newsgroup and
> will add it in LV7 though! Thanks for your comments. If you can think of
> anything else helpful definately let me know.
>


Busy-waits are often made out to be the bad guy since when implemented
badly, they can really affect performance of the system. On the
otherhand, badly implemented interupt drivers or event handlers can ruin
performance too. If you are seeing bad performance according to the
task manager or profiler, then describe what the symptom is and how that
part of the app are written. People on this forum can probably offer
insight into how it can be fixed. If the performance is fine and the
code is correct, then maybe it doesn't need to be rewritten?

My point is that in LV right now, some things are expensive, others are
cheap. LV is sent events from the OS each time the mouse moves, and
more code is executed determining what the cursor should be than is
spent properly reading and comparing some Booleans looking for a value
change. User interface events will be nice to have, but in my opinion,
for reasons other than performance. In the midst of your OS class, they
brought up sleep() because it is an important tool, just like interrupts
and events. Polled systems will probably always be with us. In fact,
USB is new and incredibly popular, but is it interrupt driven? Nope,
the devices are polled because it simplifies the bus, allows for cheaper
HW and keeps things orderly.

As for NI paying attention, myself and many other NI employees
participate in this list. It is one of the best ways for us to gather
feedback and ideas for new products.

Greg McKaskle
0 Kudos
Message 8 of 8
(3,571 Views)
I think you have to read about "State machines" in LV.
(just type these words in search).
This technique allows you to control all events in the program (such as menu selections, events from buttons and others) and organize your program in most effective way.

Oleg Chutko
0 Kudos
Message 3 of 8
(3,571 Views)
See the related thread.
http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=5065000000080000006E310000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0


LabVIEW, C'est LabVIEW

0 Kudos
Message 5 of 8
(3,571 Views)