Jump to content

Replace buttons with ComboBox or Toggle Switch?


Recommended Posts

Hi, everyone

post-6631-1169019620.gif?width=400

I am writing a LabVIEW program to test a board through COM Port, User should send commands to the board and the corresponding response should be displayed on the String indicator on the Front panel.

By now, I only know the way of using buttons to send commands, I use a "Build Array" and "Search 1D Array" to assign each button a number and do the corresponding operation in the case structure...

However, to be more user-friendly, I need to replace some of the buttons with ComboBox and Toggle Switch, since these controls are different from buttons, I did not know how to implement them...

I tried to use a Toggle switch, for each "on" or "off" state, different commands should be sent to the board. I hope command sent to the board once when user click the switch. By default, I hope nothing would happen. It seems I should use a "event structure", however, I failed to do so ...My problem is how to make the Combox or Toggle Switch act as buttons and combined these cases with buttons without conflict.

post-6631-1169019689.gif?width=400

By now, all the "value1/value2/value3/on/off" are represented by a button...

post-6631-1169020084.gif?width=400

Could anyone give me some suggestion to replace the "2403.33 MHz/2442.24 MHz/2479.10 MHz" to a Combobox and "XCEN 0/XCEN 1" to a Toggle switch??

I think I need to know more about the properties of controls...

Admin Note: Please read the following for information on how to post images on LAVA:

How to Insert Images in your Posts, Making a good first impression

Download File:post-6631-1169006264.vi

Link to comment
Hi, everyone

I tried to use a Toggle switch, for each "on" or "off" state, different commands should be sent to the board. I hope command sent to the board once when user click the switch. By default, I hope nothing would happen. It seems I should use a "event structure", however, I failed to do so ...My problem is how to make the Combox or Toggle Switch act as buttons and combined these cases with buttons without conflict.

When I said yesterday messed up portal I meant that the portal was so wide it wouldn't fit my (widescreen) window on my laptop, please host your pictures at lava

Then you definitely need the Event structure, where you said a string to write and do a read in the timeout case:

Now a trick would be set the label of the boolean to the string you want to write, and the caption to the text you want the user to see (in this case you don't even need that since you use the boolean texts), put the booleans into 2 or three clusters (the Islands you have created on your FP look nice).

The following code could be yours:

Download File:post-2399-1169010633.vi

Ton

Link to comment

Hi,

You'll have a hard time debugging apps like this. And making any extension to it will especially be difficult. You can check each time if the valueof a combobox has changed, but it's much easier to detect it with an event structure and a value change.

I see you did use the shift register to store the comm transcript. If you go for some state machine / queued message handler (for example the one I proposed to you earlier) you should put that string in the state cluster.

Joris

Link to comment
However, to be more user-friendly, I need to replace some of the buttons with ComboBox and Toggle Switch, since these controls are different from buttons, I did not know how to implement them...

Pockey,

I made a VI based on what I understood from your message. I hope that helps.

Basically, you can use event structure for any kind of controls...buttons...combo box..etc. Check out the VI.

Regards,

Ashish

Download File:post-2466-1169073863.vi

Link to comment

Thanks a lot, ashishuttarwar!

Your example shows me the usage of Toggle Switch

However, for "Combo box", the command sent is the same as the value, I hope to send "r 0x24ad" for "2403.33 MHz", how could I assign different commands to different values of a "Combo box".

In C#, it's quite easy to use a event handler and with { if(combobox.text=="2403.33 MHz") comport.write("r 0x24ad");}...

It's difficult to get the same result with LabVIEW, at least for me at this stage.

Is there any Compare or Match function in LabVIEW to compare the current select of a Combo box?

Link to comment
However, for "Combo box", the command sent is the same as the value, I hope to send "r 0x24ad" for "2403.33 MHz", how could I assign different commands to different values of a "Combo box".

In C#, it's quite easy to use a event handler and with { if(combobox.text=="2403.33 MHz") comport.write("r 0x24ad");}...

It's difficult to get the same result with LabVIEW, at least for me at this stage.

Is there any Compare or Match function in LabVIEW to compare the current select of a Combo box?

These things are not difficult in LabVIEW; you just need to think about them differently. In your case, I don't think you want to use a combo box. Instead, you could use a ring or an enumeration, which looks the same to the user, but has a numeric data type. Then, create a constant array of strings with the values you want to write to the COM port. Use the numeric value from the front panel control as an index into the array of strings to determine which string to send.

post-3989-1169125935.gif?width=400

Link to comment
Since I'm just using LabVIEW, I still did not know "Ring/Enumeration" before...

Hi,

I have modified my previous example and used ENUM instead of Combo.

You can moify ENUM values by right click menu options. Also, you can pass different values than ENUM using Case Structure.

I hope that helps.

Regards,

Ashish

Download File:post-2466-1169170639.vi

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.