Thanks for the fast responses Archie.
I'm trying to use the DataSubscribers which looks like it would work. Since I have 18 values to track, I'm trying to use one routine to manage colors and text changes for the labels sine they are basically the same except a different number being displayed. I added an AddHandler line for each DataSubscriber in the "Form New" event so that I could manage the code from one event like this:
AddHandler DataSubscriber1.DataChanged, AddressOf DataSubscriber_DataChanged
AddHandler DataSubscriber2.DataChanged, AddressOf DataSubscriber_DataChanged
AddHandler DataSubscriber3.DataChanged, AddressOf DataSubscriber_DataChanged
...
When the form first loads I get "Invoke or BeginInvoke cannot be called on a control until the window handle has been created." errors for each DataSubscribers. If I go past all of the errors, it seems to work. The DataSubscriber_DataChanged looks something like this:
Private Sub DataSubscriber_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs)
Dim ctl As MfgControl.AdvancedHMI.DataSubscriber = DirectCast(sender, MfgControl.AdvancedHMI.DataSubscriber)
Try
Dim strSection As String = ctl.PLCAddressValue.Substring(2, 2)
Dim lbl() As Control = Me.Controls.Find("lblORASection_" & strSection, False)
If lbl.Length = 1 Then
If e.Values(0) = "True" Then
lbl(0).BackColor = Color.Red
lbl(0).Text = strSection & vbCrLf & "Stopped"
Else
lbl(0).BackColor = Color.LimeGreen
lbl(0).Text = strSection & vbCrLf & "Running"
End If
End If
Catch ex As Exception
MessageBox.Show(ex.ToString, "HMI Error - DataSubscriber_DataChanged", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Should the AddHandler be done differently?
Thanks,
Chris