In other topic,
http://advancedhmi.com/forum/index.php?topic=754.0, Darrell asked for KeypadPopUp to have read button so I have been trying to accomplish reading and showing the current PLCAddressKeypad value when the Keypad pops up.
A line of your code to read the value didn't work properly with OpcDaCom:
Me.KeypadPopUp.Value = Me.m_CommComponent.Read(Me.m_PLCAddressKeypad, 1)(0)
So here is what I've done after reading your reply: just by using parts of your code, I have created a new Public Function inside the OpcDaCom:
Public Function ReadCurrentValue(ByVal PLCAddress As String) As String
If DLL Is Nothing Then CreateDLLInstance()
Dim OPCSubscriptionItem(0) As Opc.Da.Item
OPCSubscriptionItem(0) = New Opc.Da.Item
OPCSubscriptionItem(0).ItemName = PLCAddress
If m_OPCTopic IsNot Nothing AndAlso (String.Compare(m_OPCTopic, "") <> 0) Then
OPCSubscriptionItem(0).ItemName = "[" & m_OPCTopic & "]" & OPCSubscriptionItem(0).ItemName
End If
Dim values() As Opc.Da.ItemValueResult = DLL.Read(OPCSubscriptionItem)
If values.Length <= 0 OrElse values(0).ResultID.Code <> 0 Then
Throw New MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException("Failed OPC READ (OpcDaCom)")
Else
Dim ReturnedValues() As String = {Convert.ToString(values(0).Value)}
Return ReturnedValues(0)
End If
End Function
And inside KeypadHMI control I have used the following code to set KeypadPopUp.Value:
If Me.m_CommComponent.GetType().ToString = "AdvancedHMIDrivers.OpcDaCom" Then
Dim OPC As New AdvancedHMIDrivers.OpcDaCom
OPC = Me.m_CommComponent
Me.KeypadPopUp.Value = OPC.ReadCurrentValue(Me.m_PLCAddressKeypad)
Else
Me.KeypadPopUp.Value = Me.m_CommComponent.Read(Me.m_PLCAddressKeypad, 1)(0)
End If
I did a quick test with Matrikon OPC Simulator and the code appears to be working fine (not sure if there might be any side effects). The tags inside the collection have to be accurate otherwise an exception will be thrown.
I will post both files in other topic so Darrell and anyone else could use it.