Author Topic: Create a custom component with the AdvancedHMI controls and drivers  (Read 9441 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5317
    • View Profile
    • AdvancedHMI
Re: Create a custom component with the AdvancedHMI controls and drivers
« Reply #15 on: April 19, 2015, 08:35:29 AM »
Version 3.98f has been posted. I wasn't able to do much testing with User Controls, so there still may be some bugs to work out.

yubish

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Create a custom component with the AdvancedHMI controls and drivers
« Reply #16 on: April 20, 2015, 10:32:42 AM »
Hi Archie !
Thank you so much for your collaboration and for the update, the bugs are fixed (y).
I had another idea, instead of including the ethernet driver in the usecontrol, i thought if it could be possible to insert the driver only in the mainform and have a property in the usercontrol that links the driver with the advancedHMI controls of our usercontrol.
This could help us avoid using the driver in each usercontrol in the mainform. As a newbie in VB, i don't know if it's possible to do this in it.
Thank's in advance.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5317
    • View Profile
    • AdvancedHMI
Re: Create a custom component with the AdvancedHMI controls and drivers
« Reply #17 on: April 20, 2015, 04:46:54 PM »
I had another idea, instead of including the ethernet driver in the usecontrol, i thought if it could be possible to insert the driver only in the mainform and have a property in the usercontrol that links the driver with the advancedHMI controls of our usercontrol.
This is starting to get into the area of writing custom controls so it can get complicated. To fully take advantage of this, you would need to understand object oriented programming.

This is an idea of how to go about this. First you need to create a property for your UserControl that hold the driver instance:

- Right click the design surface of the UserControl and select ViewCode
- Enter this code
Code: [Select]
    Private m_CommComponent As AdvancedHMIDrivers.IComComponent
    Public Property CommComponent() As AdvancedHMIDrivers.IComComponent
        Get
            Return m_CommComponent
        End Get
        Set(ByVal value As AdvancedHMIDrivers.IComComponent)
            If m_CommComponent IsNot value Then
                m_CommComponent = value
            End If
        End Set
    End Property

Next you will need to initialize each control on the UserControl to tell it where to find it's driver to communicate:

Code: [Select]
    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        If Me.components Is Nothing Then
            Me.components = New System.ComponentModel.Container()
        End If

        '* Set the component to each control that is on the UserControl
        DigitalPanelMeter1.CommComponent = m_CommComponent
    End Sub

Now when you add the UserControl to an application's form, you will need to set the CommComponent property to a driver that you have on the form.

I do not have access to a PLC right now to fully test this, but it is the framework to do what you want.

yubish

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Create a custom component with the AdvancedHMI controls and drivers
« Reply #18 on: April 21, 2015, 06:39:17 AM »
Thank you Archie. I wrote the code in a similar way by including the initialization in the property :
 
   
Code: [Select]
Public CommComponent As AdvancedHMIDrivers.IComComponent
    Public Property CommComponent() As AdvancedHMIDrivers.IComComponent
        Get
            Return m_CommComponent
        End Get
        Set(value As AdvancedHMIDrivers.IComComponent)
            CommComponent = value
            BasicLabel3.CommComponent = value
        End Set

    End Property

It works well but i don't know if it's right.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5317
    • View Profile
    • AdvancedHMI
Re: Create a custom component with the AdvancedHMI controls and drivers
« Reply #19 on: April 21, 2015, 09:36:45 AM »
Your method works just as well and is simpler.

Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: Create a custom component with the AdvancedHMI controls and drivers
« Reply #20 on: April 27, 2015, 08:01:38 PM »
It is possible to add driver to a UserControl but the code needs to be adjusted to use that driver only and not to look for the presence of any other driver.

Check the attached picture for a simple UserControl with TrendChart, BasicLabel and BasicButton (at Runtime, left picture is before subscriptions are enabled and right picture after).

This control has a tendency of using the driver as soon as it is created in the DesignMode and that was the reason I included the button to Enable/Disable Subscriptions (the driver subscriptions are also disabled in the code = Constructor Region - Public Sub New()).

Could possibly be adjusted to behave differently.