AdvancedHMI Software

General Category => Support Questions => Topic started by: PJonHar on May 23, 2017, 08:04:50 AM

Title: Subscribe Method
Post by: PJonHar on May 23, 2017, 08:04:50 AM
Hi,

I am using the Subscribe on certain tags that a user can define via XML, which is then read in and the subscriptions made.
Code: [Select]
Private Sub QCompositeButtonPLCMessages_ItemActivated(sender As System.Object, e As Qios.DevSuite.Components.QCompositeEventArgs) Handles QCompositeButtonPLCMessages.ItemActivated
        Try
            Dim frmPLCMessages As New frmPLCMessages()
            If frmPLCMessages.ShowDialog(Me) = DialogResult.OK Then
                ApplicationPLCMessages = New PLCMessages().Load
                SubscribePLCMessages()
            End If
            frmPLCMessages = Nothing
        Catch ex As Exception
            Log.ErrorMessage(ex.TargetSite.Name, ex.Message, "1410")
        End Try
    End Sub

    Private Sub UnsubscribePLCMessages()
        For Each i As Integer In SubscriptionIDs
            PLC.UnSubscribe(i)
        Next
        SubscriptionIDs.Clear()
    End Sub

    Private Sub SubscribePLCMessages()
        UnsubscribePLCMessages()

        For Each pm As PLCMessage In ApplicationPLCMessages
            If pm.Message.Length > 0 Then
                SubscriptionIDs.Add(PLC.Subscribe(pm.Tag, 1, AddressOf SubscriptionCallback))
            End If
        Next

    End Sub

Upon initial loading of the main form the method SubscribePLCMessages is ran and the subscription works.
If i open the form frmPLCMessages and then click OK to the form the SubscribePLCMessages is re-ran to ensure any changes made to the XML file take place. However, upon this second call to SubscribePLCMessages my program hangs on the line 'PLC.Subscribe(pm.Tag, 1, AddressOf SubscriptionCallback)'.

Any Ideas?

Thanks.
Title: Re: Subscribe Method
Post by: Archie on May 23, 2017, 08:57:27 AM
What driver and what version are you using?
Title: Re: Subscribe Method
Post by: PJonHar on May 26, 2017, 09:35:52 AM
Hi Archie,

I am using the ClxDriverV111R766.
Title: Re: Subscribe Method
Post by: PJonHar on June 13, 2017, 05:48:31 PM
bump
Title: Re: Subscribe Method
Post by: Archie on June 13, 2017, 09:10:24 PM
There is a SyncLock that prevents subscription changes while they are being updated. One possibility for a call to Subscribe to hang would be this:

On a callback of subscription data returned, if you hold that and at the same time wait for a call to subscribe to finish, you will be in a grid lock situation.

Also the Subscribe method in the driver does not check for duplicate subscriptions. So if you call Subscribe with the same parameters twice, then the driver will process the callback twice for every data update.