AdvancedHMI Software

General Category => Tips & Tricks => Topic started by: Godra on January 21, 2015, 08:32:36 PM

Title: Glass Buttons
Post by: Godra 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.
Title: Re: Glass Buttons
Post by: Archie 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.
Title: Re: Glass Buttons
Post by: Godra 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)?
Title: Re: Glass Buttons
Post by: Archie 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.
Title: Re: Glass Buttons
Post by: Godra 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).
Title: Re: Glass Buttons
Post by: Archie 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.
Title: Re: Glass Buttons
Post by: Godra 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.
Title: Re: Glass Buttons
Post by: pal 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
Title: Re: Glass Buttons
Post by: Godra 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)
Title: Re: Glass Buttons
Post by: pal 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
Title: Re: Glass Buttons
Post by: Godra 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.
Title: Re: Glass Buttons
Post by: pal 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
Title: Re: Glass Buttons
Post by: Godra 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.
Title: Re: Glass Buttons
Post by: oqapsking 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!!!
Title: Re: Glass Buttons
Post by: Godra 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).
Title: Re: Glass Buttons
Post by: bachphi on October 30, 2016, 08:08:07 AM
In the downloaded demo folder, there are 2 DLL files ( GlassButton.dll, GlassButtonVB.dll). Adding either one of those will work, but not both.  I am curious to know why the author generated 2 dll files?
Title: Re: Glass Buttons
Post by: Godra on October 30, 2016, 11:22:28 AM
I would suggest that GlassButton.dll file is compiled C# code and GlassButtonVB.dll is compiled VB code.

Both of them represent the same project and that's why only one works at the time.

Take a look at the source zip file.
Title: Re: Glass Buttons
Post by: bachphi on October 30, 2016, 06:30:09 PM
..., 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.


* Edit: This should be the simplest way of adding this control to AHMI. Previously, there was another explanation with different steps, which might be reflected in the posts below.

It may be simpler, but I would recommend to follow Archie's method. The reason is if you move this project to another PC and do a build clean, your  DLL will be gone.

First,  Add the DLL file to the AdvancedHMIControls\Support using Add Existing Item.
Then Add Reference to AdvancedHMIControls project , no need to add reference to AdvancedHMI  project
Title: Re: Glass Buttons
Post by: Godra on October 30, 2016, 08:46:02 PM
Sounds good to me.

I have corrected my post to reflect that.
Title: Re: Glass Buttons
Post by: Rookie 2017 on May 11, 2017, 04:42:56 PM
HEY GUYS,

So im a complete noob to this stuff and and VERY slowly catching on.  But in this instance, I messed something up for sure.

I added the DLL file to the AdvancedHMIControls\Support, then added Reference to AdvancedHMIControls project , the button shows up and looks great! but no plc click......

Please speak slowly and use small words, lol

Thanks in advance
Title: Re: Glass Buttons
Post by: Phrog30 on May 11, 2017, 06:16:52 PM
If you download "GlassButtonHMIv399.vb" from post #1 it already has that in there.  It will have one error, I believe you need to change CommComponent, to ComComponent.  I haven't tested this, so it may not work.  But it does have the PLC properties there.
Title: Re: Glass Buttons
Post by: bachphi on April 19, 2022, 11:34:08 AM
It's been a while to revisit Godra's gem. Godra, are you still around?
Unless I am missing something, but I wanted to use it as a toggle pushbutton (Maintained PB)  and switching the button's text between Enabled/Disabled. I don't want to use PLCAddressText to select the text.  so I added the TextAlternate.

Attached is the one that included TextAlternate feature.

Also included is the dll file. Credit to Lukasz Swiatkowski.


Code: [Select]
FTV Maintained PB BACKCOLOR CAPTION TEXT PLC TAG CONNECTION
                STATE0 RED DISABLED HMI_ENABLED_I
                STATE1 GREEN ENABLED



GLASSBUTTON      OUTPUT TYPE TOGGLE
               BACK COLOR RED
               HILIGHT COLOR GREEN
               TEXT         DISABLED
               TEXT ALTERNATE ENABLED
               PLCAddressClick HMI_ENABLED_I
               PLCAddressHilight HMI_ENABLED_I
               PLCAddressSelectTextAlternate HMI_ENABLED_I