Author Topic: DataSubscriber - Heavy CPU Load??  (Read 2374 times)

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
DataSubscriber - Heavy CPU Load??
« on: April 15, 2016, 08:11:45 PM »
Hi,

First of all thanks for the great library!

I have started a project and I am using the DataSubscriber in order to get notified of when a Tag changes value:
Code: [Select]
  Private ds As New AdvancedHMIControls.DataSubscriber

With ds
                .CommComponent = PLCConnection

                AddHandler .DataChanged, AddressOf DataChangedCallback
                .PLCAddressValue = "Value1"
                .PLCAddressValue = "Value2"
                .PLCAddressValue = "Value3"
                .PLCAddressValue = "Value4"

End With

However, When i run the project, all of my cpu cores pretty much max out and if i profile the application running there seems to be a thread for each of the subscriptions on the data subscriber, but they don't seem to be taking a great percentage of processing (see picture 1). The profile application also notices that 30+ other threads (see picture 2) have been created and running?

I am doing this the wrong way or is something not right?

Thanks,

Paul

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: DataSubscriber - Heavy CPU Load??
« Reply #1 on: April 16, 2016, 12:33:26 AM »
A few things to note about the DataSubscriber:

- The DataSubscriber can only subscribe to a single variable. You will either need to use multiple DataSubscribers or the DataSubscriber2
- The DataSubscriber implements ISupportInitialize which means you must call BeginInit before setting properties, then calling EndInit
- The DataSubscriber was designed for use with the visual designer to simply subscribing. If using it in code, it is more efficient to subscribe directly to the driver

Try this test to see if it works:

- Open a fresh copy of the AdvancedHMI solution
- Build the project
- Open the MainForm
- From the ToolBox, add a driver instance to the form
- From the All Windows Form group, add 2 Labels to the form
- Add a DataSubscriber2 to the form
- In the Properties window, click in PLCAddressValueItems, then click the ellipsis button to open the window to add items
- Add 2 items and put an address in PLCAddress for each item
- Double click the DataSubscriber to get back to the code
- Enter this code:
Code: [Select]
    Private Sub DataSubscriber21_DataChanged_1(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
        If String.Compare(e.PlcAddress, DataSubscriber21.PLCAddressValueItems(0).PLCAddress) = 0 Then
            Label2.Text = e.Values(0)
        End If

        If String.Compare(e.PlcAddress, DataSubscriber21.PLCAddressValueItems(1).PLCAddress) = 0 Then
            Label3.Text = e.Values(1)
        End If
    End Sub

Run the application and see if the 2 labels show the values and check your CPU usage.

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: DataSubscriber - Heavy CPU Load??
« Reply #2 on: April 16, 2016, 08:06:10 PM »
Hi,

Thanks for the prompt reply!

So I added a DataSubscriber2 from the ToolWindow. I still populate the PLCAddress List via code. The threads are reduced greatly! (See picture 'threads').
However, The Immediate Window of Visual Studio when debugging is constantly populating with:

Code: [Select]
'A first chance exception of type 'MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException' occurred in MfgControl.AdvancedHMI.Drivers.dll'
See picture 'immediate window'.

Any Ideas?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: DataSubscriber - Heavy CPU Load??
« Reply #3 on: April 16, 2016, 09:57:35 PM »
Are you calling DataSubscriber21.BeginInit before adding the items, then EndInit afterwards?

There should only be one subscription thread per driver instance. The latest release does have a known issue in the CLX driver that causes these multiple threads. There is a patched version that was made for testing.
« Last Edit: April 17, 2016, 01:47:34 PM by Archie »

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: DataSubscriber - Heavy CPU Load??
« Reply #4 on: April 17, 2016, 12:13:33 PM »
Hi,

I have referenced the newly patched library but there is no BeginInit and EndInit?

Thanks

Paul

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: DataSubscriber - Heavy CPU Load??
« Reply #5 on: April 17, 2016, 01:27:29 PM »
I see the problem. Under the AdvancedHMIControls projects in the \components folder, edit DataSubscriber2.vb

Go to line 213, change that sub from Private to Public

Then line 217 and do the same thing.

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: DataSubscriber - Heavy CPU Load??
« Reply #6 on: April 17, 2016, 02:28:34 PM »
Thanks Archie,

That is looking better (see picture).

When running in debug with the newly patched driver, the immediate window is still populating with the error:

Code: [Select]
'A first chance exception of type 'MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException' occurred in MfgControl.AdvancedHMI.Drivers.dll'
Cheers,

Paul

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: DataSubscriber - Heavy CPU Load??
« Reply #7 on: April 17, 2016, 02:50:31 PM »
You could go to Debug->Exceptions and set it to throw on Common Language Runtime exceptions to see if it shows you more details of where the exception occurs. Since it is a handled exception on the DLL, it may not show anything,

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: DataSubscriber - Heavy CPU Load??
« Reply #8 on: April 17, 2016, 03:05:31 PM »
Have done that, Is the attached of any meaningful information?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: DataSubscriber - Heavy CPU Load??
« Reply #9 on: April 17, 2016, 03:18:59 PM »
That is an error (CIP General Status) returned directly from your PLC:

0F    Privilege violation    A permission/privilege check failed

Maybe you are trying to access a tag that does not have external read access?


A Wireshark capture would be the next thing to figure out what request is returning the error.

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: DataSubscriber - Heavy CPU Load??
« Reply #10 on: April 18, 2016, 07:07:48 AM »
Just to let you know, the issue with the ever appearing message:

0F    Privilege violation    A permission/privilege check failed

Was actually that I was trying to access a tag that didn't exist.
Would it be possible to the Data Subscriber to check that the tag exists before adding it to its subscription thread, thus eliminating the need to keep checking for it?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: DataSubscriber - Heavy CPU Load??
« Reply #11 on: April 18, 2016, 08:10:39 AM »
The drivers are designed for automatic recovery, so the subscription items stay in the list and continually re-try. Normally the subscriptions are used by visual controls like the BasicLabel which will show any problems with an address.

An non-existent tag will normally give a Path Segment Error. I'm not sure why in your case you were getting the Privilege Violation.