Here are the pieces of code that you need to place in WaterPump.vb
'*****************************************
'* Property - Address in PLC to Link to
'*****************************************
Private m_PLCAddressClick As String = ""
<System.ComponentModel.Category("PLC Properties")> _
Public Property PLCAddressClick() As String
Get
Return m_PLCAddressClick
End Get
Set(ByVal value As String)
If m_PLCAddressClick <> value Then
m_PLCAddressClick = value
End If
End Set
End Property
'****************************
'* Event - Mouse Down
'****************************
Private Sub MomentaryButton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If (m_PLCAddressClick IsNot Nothing AndAlso (String.Compare(m_PLCAddressClick, "") <> 0)) And Enabled AndAlso m_CommComponent IsNot Nothing Then
Try
Select Case OutputType
Case MfgControl.AdvancedHMI.Controls.OutputType.MomentarySet : m_CommComponent.Write(m_PLCAddressClick, 1)
Case MfgControl.AdvancedHMI.Controls.OutputType.MomentaryReset : m_CommComponent.Write(m_PLCAddressClick, 0)
Case MfgControl.AdvancedHMI.Controls.OutputType.SetTrue : m_CommComponent.Write(m_PLCAddressClick, 1)
Case MfgControl.AdvancedHMI.Controls.OutputType.SetFalse : m_CommComponent.Write(m_PLCAddressClick, 0)
Case MfgControl.AdvancedHMI.Controls.OutputType.Toggle
Dim CurrentValue As Boolean
CurrentValue = m_CommComponent.Read(m_PLCAddressClick, 1)(0)
If CurrentValue Then
m_CommComponent.Write(m_PLCAddressClick, 0)
Else
m_CommComponent.Write(m_PLCAddressClick, 1)
End If
Case Else
End Select
If tmrError.Enabled Then
tmrError.Enabled = False
End If
Catch ex As Exception
DisplayError("WRITE FAILED!" & ex.Message)
End Try
End If
Me.Invalidate()
End Sub
'****************************
'* Event - Mouse Up
'****************************
Private Sub MomentaryButton_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
If (m_PLCAddressClick IsNot Nothing AndAlso (String.Compare(m_PLCAddressClick, "") <> 0)) And Enabled AndAlso m_CommComponent IsNot Nothing Then
Try
Select Case OutputType
Case MfgControl.AdvancedHMI.Controls.OutputType.MomentarySet : m_CommComponent.Write(m_PLCAddressClick, 0)
Case MfgControl.AdvancedHMI.Controls.OutputType.MomentaryReset : m_CommComponent.Write(m_PLCAddressClick, 1)
End Select
Catch ex As Exception
DisplayError("WRITE FAILED!" & ex.Message)
End Try
End If
Me.Invalidate()
End Sub
Private m_OutputType As MfgControl.AdvancedHMI.Controls.OutputType = MfgControl.AdvancedHMI.Controls.OutputType.MomentarySet
Public Property OutputType() As MfgControl.AdvancedHMI.Controls.OutputType
Get
Return m_OutputType
End Get
Set(ByVal value As MfgControl.AdvancedHMI.Controls.OutputType)
m_OutputType = value
End Set
End Property