Author Topic: OpcDaCom Driver to return current value  (Read 3800 times)

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
OpcDaCom Driver to return current value
« on: May 21, 2015, 11:53:51 PM »
Currently, it seems that this driver updates the returned value only when there was a change in that particular value.

This I noticed while using KeypadHMI control where the initial reading of any PLC address would return its current value but when addresses were changed back and forth, with no change of data in either address, then it would just keep on showing the very last address value. If the data has changed for any of the addresses then it would show that new value when that particular address was selected.

Is it possible to have the driver return the current value of the polled address regardless of whether it has changed since the last reading?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: OpcDaCom Driver to return current value
« Reply #1 on: May 22, 2015, 10:03:41 AM »
Are you changing the PLCAddressValue of a control, then it doesn't update the value to the value of  the new tag? OPC works on a DataChanged callback, so you only get data updates from teh OPC Server when the value changes. This would even occur when you first subscribe to a value, so the OpcDaCom driver will perform an initial read of the value when first subscribing. You can see this at line 465 of the opcDaCom.vb driver

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: OpcDaCom Driver to return current value
« Reply #2 on: May 22, 2015, 08:36:39 PM »
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:

Code: [Select]
    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:

Code: [Select]
            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.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: OpcDaCom Driver to return current value
« Reply #3 on: June 12, 2015, 07:43:06 PM »
The above posts have become kind of obsolete since the next release of AHMI, post 3.98n, will have the OpcDaCom driver Read function corrected to accept the only needed line of code:

Code: [Select]
Me.KeypadPopUp.Value = Me.m_CommComponent.Read(Me.m_PLCAddressKeypad, 1)(0)