LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to link a menu selection on the front panel buttons/controls

I have a VI which can run few tests through some analogue and digital I/Os. I have placed "buttons" on the front panel to start each of the tests. Now I would like to create "menu selection" as well so during execution, if one wish to run a test then one can run it by selecting from menu selection or pressing a button.
 
How can I link the two areas to run one selection?
 
 
0 Kudos
Message 1 of 10
(4,076 Views)
The best way to handle this is with a producer-consumer architecture. This will allow you to have each event tell the consumer loop to go to the same state. See this KB article for more information on this architecture: http://zone.ni.com/devzone/cda/tut/p/id/3023.
0 Kudos
Message 2 of 10
(4,067 Views)
Thank you for your answer but this is not I am looking for. I would just like to link menu selection to a button on the front panel i.e. When program is running, If one selects File>Tests> Test loudspeaker from menu selection tab or a button "Test loudspeaker" press from the front panel both do the same job by calling the case releated to test loudspeker. So, how would I link menu selection with a button on a front panel?
0 Kudos
Message 3 of 10
(4,048 Views)
As far as I know, a direct link is not possible.
The best way of getting a UI action is the event structure to handle buttons and menu(s), and sooner or later you end up in the producer-consumer- architecture ....
However you can 'push the button' via properties and this can be done in that region(state) of your diagram, that handles the menu events , BUT  that is bad coding style ....
... and I'm not shure if bad style is better than no style Smiley Wink


Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 4 of 10
(4,045 Views)
Hi,

I've done this in my program using a the value(signaling) property of the button, see the example. It seems to work fine.

Henrik, is this what you had in mind and if so why is it bad coding style? I'm quite happy to accept that it is but I'd like to the know the reason, and what is the alternative. Having a button and a menu item to that do the same thing (presumably by activating the same code) is quite a common thing (in labview and non labview programs) so there must be a correct or preffered way to do it.

Thanks
David




Message Edited by DavidU on 06-24-2008 01:39 PM

Message Edited by DavidU on 06-24-2008 01:39 PM
0 Kudos
Message 5 of 10
(4,029 Views)
I personally consider it bad coding style because it requires you to:
  1. Change the default mechanical action of a button.
  2. Remember to initially write a False to the button in case it was left pressed down (as your code does).
  3. Read the button's state so you can set it to the opposite.
With respect to other programming languages, it's true that it's quite common to have a button (such as a toolbar button) and a menu item do the same thing. However, in this case the event handler for the two actions end up calling the same function. At least that's the way I code, since it would be silly to duplicate code in both event handlers. Carrying that over to LabVIEW one can say that the code that is performed by the event would be in a subVI and you would place the subVI in the same event case.

As I noted in my initial response, the best way to handle this is with a producer-consumer architecture. It's a robust architecture and well worth learning. It's obviously not the only way. If I didn't want to set up a producer-consumer architecture I would use the subVI route rather than the Value (Signaling) property as your example shows. But that's just me. Smiley Wink
Message 6 of 10
(4,015 Views)
Fair points, particularly #2 - that's always annoyed me. I better add this to the list of 'things to do to improve my code'Smiley Very Happy

thanks
Dave


Message Edited by DavidU on 06-25-2008 09:09 AM
0 Kudos
Message 7 of 10
(4,000 Views)

Thanks for everyone's reply.

David- Would you please send me a snapshot of your vi as I can not open the attached vi due to LabVIEW version 7.1 on my computer. From the thread it looks there is a place for an improvment in your vi. However, it would give me good understanding of it.

Thanks,

Mayur

0 Kudos
Message 8 of 10
(3,989 Views)
Mayur

Ok, but as smercurio has pointed out this is not the best way to do it and you would be better off in the long run doing it the right way now.Smiley Wink

The first attachment is my original code - Top image is the whole code and the bottom two images are the extra event cases.

The second attachment is if you want your button to latch rather than switch. Since you can't use the value signalling property with a latch mechanism you have to change the buttons behaviour and recreate the latch by setting the button back to false in its event case. This is smercurios point 1 and it needs a local variable - which isn't ideal. Using latch behaviour you don't need to read the button state in the menu activation - just use a true constant.

Dave
Download All
0 Kudos
Message 9 of 10
(3,970 Views)

Hi.. I am facing the same problem. I cant duplicate the code because its a pretty big block. How can i do it without duplicating?

0 Kudos
Message 10 of 10
(3,610 Views)