Thanks Archie. I guess that was my original question, what all is involved. Can you check me on this, I just created a textbox that is populated by a PLC value. This works, but curious if I'm not in keeping with good .NET practice:
Public Class textbox_PLC
Inherits TextBox
#Region "Constructor"
Public Sub New()
MyBase.New()
End Sub
'****************************************************************
'* UserControl overrides dispose to clean up the component list.
'****************************************************************
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing Then
If SubScriptions IsNot Nothing Then
SubScriptions.dispose()
End If
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
#End Region
#Region "Basic Properties"
#End Region
#Region "Private Methods"
#End Region
#Region "PLC Related Properties"
'*****************************************************
'* Property - Component to communicate to PLC through
'*****************************************************
Private m_ComComponent As MfgControl.AdvancedHMI.Drivers.IComComponent
<System.ComponentModel.Category("PLC Properties")>
Public Property ComComponent() As MfgControl.AdvancedHMI.Drivers.IComComponent
Get
Return m_ComComponent
End Get
Set(ByVal value As MfgControl.AdvancedHMI.Drivers.IComComponent)
If m_ComComponent IsNot value Then
If SubScriptions IsNot Nothing Then
SubScriptions.UnsubscribeAll()
SubScriptions.ComComponent = value
End If
m_ComComponent = value
SubscribeToComDriver()
End If
End Set
End Property
Private m_PLCAddressText As MfgControl.AdvancedHMI.Drivers.PLCAddressItem
<System.ComponentModel.DefaultValue("")>
<System.ComponentModel.Category("PLC Properties")>
Public Property PLCAddressText() As MfgControl.AdvancedHMI.Drivers.PLCAddressItem
Get
Try
Return m_PLCAddressText
Catch ex As Exception
Return Nothing
End Try
End Get
Set(ByVal value As MfgControl.AdvancedHMI.Drivers.PLCAddressItem)
If ((value Is Nothing Or m_PLCAddressText Is Nothing) OrElse ((value.GetType) Is (m_PLCAddressText.GetType))) Then
Try
If m_PLCAddressText IsNot value Then
m_PLCAddressText = value
End If
Try
'* When address is changed, re-subscribe to new address
SubscribeToComDriver()
Catch
End Try
Catch
End Try
End If
End Set
End Property
#End Region
#Region "Events"
'********************************************************************
'* When an instance is added to the form, set the comm component
'* property. If a comm component does not exist, add one to the form
'********************************************************************
Protected Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
If Me.DesignMode Then
'********************************************************
'* Search for AdvancedHMIDrivers.IComComponent component in parent form
'* If one exists, set the client of this component to it
'********************************************************
Dim i As Integer = 0
While m_ComComponent Is Nothing And i < Me.Site.Container.Components.Count
If Me.Site.Container.Components(i).GetType.GetInterface("IComComponent") IsNot Nothing Then m_ComComponent = Me.Site.Container.Components(i)
i += 1
End While
'************************************************
'* If no comm component was found, then add one and
'* point the ComComponent property to it
'*********************************************
If m_ComComponent Is Nothing Then
m_ComComponent = New AdvancedHMIDrivers.EthernetIPforCLXCom(Me.Site.Container)
End If
Else
SubscribeToComDriver()
End If
End Sub
#End Region
#Region "Subscribing and PLC data receiving"
Private SubScriptions As SubscriptionHandler
'**************************************************
'* Subscribe to addresses in the Comm(PLC) Driver
'**************************************************
Private Sub SubscribeToComDriver()
If Not DesignMode And IsHandleCreated Then
'* Create a subscription handler object
If SubScriptions Is Nothing Then
SubScriptions = New SubscriptionHandler
SubScriptions.Parent = Me
AddHandler SubScriptions.DisplayError, AddressOf DisplaySubscribeError
End If
SubScriptions.ComComponent = m_ComComponent
SubScriptions.SubscribeAutoProperties()
End If
End Sub
'***************************************
'* Call backs for returned data
'***************************************
Private OriginalText As String
Private Sub PolledDataReturned(ByVal sender As Object, ByVal e As SubscriptionHandlerEventArgs)
End Sub
Private Sub DisplaySubscribeError(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
'DisplayError(e.ErrorMessage)
End Sub
#End Region
End Class