Author Topic: Glass Buttons  (Read 25839 times)

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Glass Buttons
« on: January 21, 2015, 08:32:36 PM »
And here you can find a nice looking Glass Button which can easily be converted to AHMI control:

http://lukesw.net/articles/GlassButton.aspx

The link above doesn't seem to be valid any longer, so try either of these:

https://www.codeproject.com/Articles/17695/Creating-a-Glass-Button-using-GDI
https://www.codeproject.com/Articles/18000/Enhanced-GlassButton-using-GDI


Download demo file that contains the library, add this library as reference to both AdvancedHMI and AdvancedHMIControls projects and then download and add the attached GlassButtonHMI.vb file to the PurchasedControls folder as ExistingItem.

It supports an image showing in the button (check the attached picture with icon file used as image).
Animated GIFs are also supported and you can find some here:

https://www.animatedimages.org

The only way to control animation is to have the button disabled, but still visible, and once enabled by some event the animation will be running (maybe there is another way but I still need to discover it).

* Edit: There is a simpler and safer way of adding this control to AHMI. Read bachphi's post on the 2nd page.
« Last Edit: January 08, 2021, 10:55:49 PM by Godra »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Glass Buttons
« Reply #1 on: January 21, 2015, 09:00:43 PM »
Nice find. I split this into it's own thread so it wouldn't get lost in the other thread.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Glass Buttons
« Reply #2 on: January 21, 2015, 09:23:19 PM »
Separate thread should work better.

This button could be used as just image holder, without functioning as button, that way animated GIF could have a good purpose (but could serve as a button as well).

I do have a question for you if there is possibility to create PLCAddressEnabled property to control the current Enabled property through a PLC address instead of creating a code (or list of steps for doing it)?
« Last Edit: January 22, 2015, 05:27:16 PM by Godra »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Glass Buttons
« Reply #3 on: January 21, 2015, 09:45:51 PM »
You can add PLC control of any property by adding this line of code to the class similar to this:

Public Property PLCAddressEnabled as string

The SubscriptionHandler searches the control for a property that matches the name after PLCAddress and hooks it to a subscription.
« Last Edit: January 21, 2015, 11:04:20 PM by Archie »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Glass Buttons
« Reply #4 on: January 21, 2015, 10:53:01 PM »
Either I am doing it wrong or it just doesn't work.

This "Enabled" property appears to be inherited from Windows Button control, since I have:

Class GlassButton --> Inherits Button
Class GlassButtonHMI --> Inherits GlassButton

Here is the property I created:

Code: [Select]
    '*****************************************
    '* Property - Address in PLC to Link to
    '*****************************************
    Private _PLCAddressEnabled As String = ""
    <System.ComponentModel.Category("PLC Properties")> _
    Public Property PLCAddressEnabled() As String
        Get
            Return _PLCAddressEnabled
        End Get
        Set(ByVal value As String)
            If _PLCAddressEnabled <> value Then
                _PLCAddressEnabled = value

                '* When address is changed, re-subscribe to new address
                SubscribeToCommDriver()
            End If
        End Set
    End Property

This new property shows and I can enter a PLC address but it just doesn't do anything to Enabled property.

I did try to create a new Enabled property in the GlassButton class, which overloads the Enabled property of the Windows Button control, but that didn't work either.

It's not a big deal to have this property, but if there is a way it would be nice to have (at least in my opinion).
« Last Edit: January 22, 2015, 05:26:41 PM by Godra »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Glass Buttons
« Reply #5 on: January 21, 2015, 11:11:49 PM »
It looks like everything is right in your code. You can put a breakpoint in the SubscibeAutoProperties subroutine in SubscriptionHandler.vb then step through to see if it finds the matching Enabled property.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Glass Buttons
« Reply #6 on: January 22, 2015, 01:11:39 AM »
Since I am not familiar with using breakpoint and stepping through the code, which I tried for a little while, here is what I tried:

- Use a copy of SquareIlluminatedButton.vb to convert GlassButton to AHMI control
-- Add OutputType property to it since it was missing and error was showing (which I then copied from BasicButton)
-- Add PLCAddressEnabled property to it as well

I will have a guess and say that SquareIlluminatedButton control was inheriting OutputType property from MfgControl.AdvancedHMI.Controls.SquareIlluminatedButton and that's why I was getting error.

And now it works and responds to a PLC address and changes Enabled property.
I am still not sure why BasicButton wouldn't do the same.

>>>  For those who decide to try to create this control, just follow the steps from the 1st post. <<<

This will give you an option to Enable/Disable button with a PLC address bit.
« Last Edit: February 20, 2016, 11:47:31 PM by Godra »

pal

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Glass Buttons
« Reply #7 on: February 05, 2015, 04:10:45 PM »
Hi Godra ,
 I've tried importing the glass button to advanced HMI following the steps in your 1st post . I opened the button in vb 2010 and converted the code with no errors . I added a new class to the Purchased Controls folder and changed the name to GlassButton.vb . I replaced the code with the code from GlassButton.vb .
on building Advanced HMI , I am getting 7 errors and 1 warning.
The 1st error comes from the initializeComponent() command on rung 25    (just before the timer )
The rest of the errors come from rugers which reference the timer.
The warning comes from the reference just above the timer with 3 ''' in front.
I am a complete novice when it comes to VB 2010  , so what have I done wrong ?
Any help you can give would be much appreciated .
Paul

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Glass Buttons
« Reply #8 on: February 05, 2015, 08:22:00 PM »
I am not sure about this, since I am not a professional programmer, but here is what you can try:

1) Remove the GlassButton.vb class from the "Purchased Controls" folder
2) Right click the folder and click "Add" --> "Existing Item" and then browse to GlassButton folder, wherever you extracted it from downloaded zip file, go to GlassButtonVB folder and select GlassButton.designer.vb
3) Ignore all the errors and just the do same steps and add GlassButton.vb (I answered "No" to a prompt about overwriting the existing designer vb file)
4) The only warning that I got was referencing the XML comment for a tag with 'cref' attribute, which it would ignore anyway (it will go away if you remove "<" and "/>" from that line)
5) Close all open forms and rebuild the project

If you still have errors then you might need to add or check references, right click the project and go to Properties window, select References and in the Imported Namespaces try to check all those that appear on top of the GlassButton.vb as "Imports".

I just tried these 5 steps listed above in version 3.8.4 and it worked.

Depending on the AHMI version that you are using, you might get some other errors once you try to create AHMI GlassButton control (this since every new version might implement code changes in certain classes). Try to use common sense and just copy and paste, or remove, one property at the time to see how it reflects on the control. In the file that was posted previously you might notice that there is no PLCAddressValue property, this since there is no "Value" property either so I didn't think that it would do anything useful and removed it (which I might be wrong about).

From what I've seen so far, some output types might not work correctly (Momentary Set, Momentary Reset, Set True, Set False appear to work fine but I couldn't get Toggle and Write Value to work with OPC Simulator). <-- Tried this with MicroLogix PLC and Toggle works fine, only WriteValue I am still not sure how to use properly (if Archie could provide a hint that would help)
« Last Edit: February 06, 2015, 06:45:43 PM by Godra »

pal

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Glass Buttons
« Reply #9 on: February 06, 2015, 04:28:10 PM »
Thanks for your reply Godra , I will try over the weekend . I'm using 397e though that might change when "f" is released . Will let you know how i get on .
Paul

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Glass Buttons
« Reply #10 on: February 06, 2015, 05:41:33 PM »
You are welcome.

I just tried the steps in fresh clean v397e project (Ctrl+Shift+B and add a driver to the form prior to doing any of the steps).

It created a GlassButton control without issues, besides for the XML comment, and also creating AHMI GlassButton control was without any issues (I used the code from the posted file).

I did edit a few things in the previous post so read them and hopefully it will work for you as well.

pal

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Glass Buttons
« Reply #11 on: February 17, 2015, 03:12:37 PM »
It took me a while but I finally found time to play and with the help of yor updated instructions Godra , it's worked .
Thank you for the time and effort you've put into the Glass Buttons for AdvancedHMI .
Paul

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Glass Buttons
« Reply #12 on: February 17, 2015, 08:22:15 PM »
Sounds good and other people should try it as well.

Also, if you haven't already, try the LED Matrix Control since it is a neat thingy.

Archie has created files so you don't have to go through similar experience as with GlassButton.

oqapsking

  • Full Member
  • ***
  • Posts: 178
    • View Profile
Re: Glass Buttons
« Reply #13 on: October 16, 2016, 11:31:13 PM »
I am not sure about this, since I am not a professional programmer, but here is what you can try:

1) Remove the GlassButton.vb class from the "Purchased Controls" folder
2) Right click the folder and click "Add" --> "Existing Item" and then browse to GlassButton folder, wherever you extracted it from downloaded zip file, go to GlassButtonVB folder and select GlassButton.designer.vb
3) Ignore all the errors and just the do same steps and add GlassButton.vb (I answered "No" to a prompt about overwriting the existing designer vb file)
4) The only warning that I got was referencing the XML comment for a tag with 'cref' attribute, which it would ignore anyway (it will go away if you remove "<" and "/>" from that line)
5) Close all open forms and rebuild the project

If you still have errors then you might need to add or check references, right click the project and go to Properties window, select References and in the Imported Namespaces try to check all those that appear on top of the GlassButton.vb as "Imports".

I just tried these 5 steps listed above in version 3.8.4 and it worked.

Depending on the AHMI version that you are using, you might get some other errors once you try to create AHMI GlassButton control (this since every new version might implement code changes in certain classes). Try to use common sense and just copy and paste, or remove, one property at the time to see how it reflects on the control. In the file that was posted previously you might notice that there is no PLCAddressValue property, this since there is no "Value" property either so I didn't think that it would do anything useful and removed it (which I might be wrong about).

From what I've seen so far, some output types might not work correctly (Momentary Set, Momentary Reset, Set True, Set False appear to work fine but I couldn't get Toggle and Write Value to work with OPC Simulator). <-- Tried this with MicroLogix PLC and Toggle works fine, only WriteValue I am still not sure how to use properly (if Archie could provide a hint that would help)



i tried to do it
but after i   "Add" --> "Existing Item" (GlassButtonHMIv399.vb)
it gives me 17 error witch is in the picture!!!

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Glass Buttons
« Reply #14 on: October 17, 2016, 12:10:35 PM »
If you check the first post it states that you have to download dll library and reference it in both projects.

Then, once you add the control, you should only get 1 error related to CommComponent which just needs to be renamed to ComComponent (one m instead of two).