Author Topic: OpcDaCom driver once subscribed doesn't observe DisableSubscriptions setting  (Read 1804 times)

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Archie,

So far, I tried this only in version 3.98t.

If DisableSubscriptions is set to True initially then it is observed until changed.
But once it is set to False it just stays subscribed regardless of how I set it afterwards through the code of a button click event (this button is used to enable/disable subscriptions).

Any thoughts?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
In OpcDaCom.vb at line 152, try this to see if it works:
Code: [Select]
    '**************************************************************
    '* Stop the polling of subscribed data
    '**************************************************************
    Private m_DisableSubscriptions As Boolean
    Public Property DisableSubscriptions() As Boolean Implements IComComponent.DisableSubscriptions
        Get
            Return m_DisableSubscriptions
        End Get
        Set(ByVal value As Boolean)
            If m_DisableSubscriptions <> value Then
                m_DisableSubscriptions = value
                If SubscriptionState IsNot Nothing Then
                    SubscriptionState.Active = Not m_DisableSubscriptions
                End If
            End If
        End Set
    End Property

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
It didn't work.

Here is what kind of works, if I don't make any changes to the property and leave it as is:

Code: [Select]
    '**************************************************************
    '* Stop the polling of subscribed data
    '**************************************************************
    Private m_DisableSubscriptions As Boolean
    Public Property DisableSubscriptions() As Boolean Implements IComComponent.DisableSubscriptions
        Get
            Return m_DisableSubscriptions
        End Get
        Set(ByVal value As Boolean)
            If m_DisableSubscriptions <> value Then
                m_DisableSubscriptions = value
            End If
        End Set
    End Property

and then just add If condition at the end of DataChangedCallBack:

Code: [Select]
    Private Sub DataChangedCallBack(ByVal clientHandle As Object, ByVal requestHandle As Object, ByVal values() As Opc.Da.ItemValueResult)
        For i = 0 To values.Length - 1
            Dim ReturnedValues() As String = {Convert.ToString(values(i).Value)}
            Dim PolledAddress As PolledAddressInfo = DirectCast(values(i).ClientHandle, PolledAddressInfo)

            'For j = 0 To Subscription.Items.Count - 1
            'If PolledAddress.OPCItem.ItemName = DirectCast(Subscription.Items(j).ClientHandle, PolledAddressInfo).OPCItem.ItemName Then

            Dim PLCAddress As String = values(i).ItemName
            '* If there is a Topic, strip it back off before sending back to subscriber
            If m_OPCTopic IsNot Nothing AndAlso Not String.IsNullOrEmpty(m_OPCTopic) Then
                PLCAddress = PLCAddress.Substring(m_OPCTopic.Length + 2)
            End If

            If Not Me.m_DisableSubscriptions Then
                Dim x As New MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs(ReturnedValues, PLCAddress, 0)
                x.SubscriptionID = PolledAddress.ID
                Dim z() As Object = {Me, x}
                m_SynchronizingObject.BeginInvoke(PolledAddress.dlgCallBack, z)
            End If
            'End If
            'Next
        Next
    End Sub

Now, if I disable subscriptions then the control is showing the last value it received and is not getting updated value (even though I still keep on changing that value with another control).

The only issue is that when I enable subscriptions again, if the value is different from what the control received last, it doesn't get shown and will be updated only with the next change of that value.

So, I guess that when enabling subscriptions all the subscribed values would have to be re-read somehow.
« Last Edit: July 20, 2015, 06:30:08 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Archie,

This driver is designed to work on DataChange and kind of implies that it currently cannot support DisableSubsriptions feature.

The example would be my previous post which suggests that if values change while subscriptions are disabled then there has to be a way of refreshing them when subscriptions are enabled.

Edit:  I was wrong. Just found a way of refreshing the values when DisableSubscriptions property is set at DesignTime or being changed at Runtime, and here is the code:

Code: [Select]
    '**************************************************************
    '* Stop the polling of subscribed data
    '**************************************************************
    Private flagSubscriptions1stRun As Boolean
    Private m_DisableSubscriptions As Boolean
    Public Property DisableSubscriptions() As Boolean Implements IComComponent.DisableSubscriptions
        Get
            Return Me.m_DisableSubscriptions
        End Get
        Set(ByVal value As Boolean)
            If Me.m_DisableSubscriptions <> value Then
                Me.m_DisableSubscriptions = value
                If Not Me.DesignMode Then
                    If Not Me.flagSubscriptions1stRun Then
                        Me.flagSubscriptions1stRun = True
                        Exit Property
                    End If
                    If Not Me.m_DisableSubscriptions Then
                        For Each subscription As Opc.Da.Subscription In DLL.Subscriptions
                            subscription.Refresh()
                        Next
                    End If
                End If
            End If
        End Set
    End Property

This might possibly be improved to refresh only the collection related to the specific instance of the driver. The DataChangedCallBack modification from previous post still has to be included.

Archie, would this be something you would consider including in the driver or do you have any other changes for the future versions?
« Last Edit: July 20, 2015, 08:49:54 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Archie,

Would you have any thoughts/comments on that solution I provided in the previous post?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
I haven't had the opportunity to look at this yet. I was thinking there must be someway to essentially pause the subscriptions within the OPC server.

As for the data read when restarting, when subscribing the driver has to force an initial read because the DataChanged will not fire until two different values are read.

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Pausing the subscriptions at the server would be ideal solution and would reduce communications as well.

As for reading the data after enabling subscriptions, if the server is to perform initial read again then there would be no need for the built-in subscriptions Refresh() option (even though, if considered, seems to work fine).