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:
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.