Author Topic: Monitor different tags with DataSubscriber2 help  (Read 184 times)

texasdru92

  • Newbie
  • *
  • Posts: 2
    • View Profile
Monitor different tags with DataSubscriber2 help
« on: January 13, 2025, 02:31:49 PM »
I'm not sure what I'm doing wrong, but I'm trying to use a DataSubscriber2 to get a basicIndicator color to change when a specific PLC tag is true. I have tried two different ways:

First
Code: [Select]
    Private Sub Divert3_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles Divert3.DataReturned
        Dim full As Boolean = False
        Dim half_full As Boolean = False

        If e.PlcAddress = "SORT_LANE3_HALF_FULL_TIMER.DN" Then
            If e.Values(0) = True Then
                Divert_3.Color1 = Color.Yellow
                half_full = True
            End If
        End If

        If e.PlcAddress = "SORT_LANE3_FULL_TIMER.DN" Then
            If e.Values(0) = True Then
                Divert_3.Color1 = Color.Blue
                full = True
            End If
        End If

        If e.PlcAddress = "SORT_LANE3_ACTIVE" Then
            If e.Values(0) = True And half_full = False And full = False Then
                Divert_3.Color1 = Color.Green
            End If
        End If

Second
Code: [Select]
    Private Sub Divert6_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles Divert6.DataReturned
        Dim full As Boolean = False
        Dim half_full As Boolean = False
        Dim active As Boolean = False

        If e.PlcAddress = "SORT_LANE6_FULL_TIMER.DN" Then
            If e.Values(0) = True Then
                'Divert_6.Color1 = Color.Blue
                full = True
            End If
        End If



        If e.PlcAddress = "SORT_LANE6_ACTIVE" Then
            If e.Values(0) = True Then
                'Divert_6.Color1 = Color.Green
                active = True
            End If
        End If

        If e.PlcAddress = "SORT_LANE6_HALF_FULL_TIMER.DN" Then
            If e.Values(0) = True Then
                'Divert_6.Color1 = Color.Yellow
                half_full = True
            End If
        End If

        If active And Not half_full And Not full Then
            Divert_6.Color1 = Color.Green
        ElseIf active And full And half_full Then
            Divert_6.Color1 = Color.Blue
        ElseIf active And Not full And half_full Then
            Divert_6.Color1 = Color.Yellow
        End If

    End Sub
« Last Edit: January 13, 2025, 02:34:38 PM by texasdru92 »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5342
    • View Profile
    • AdvancedHMI
Re: Monitor different tags with DataSubscriber2 help
« Reply #1 on: January 13, 2025, 03:44:40 PM »
First, any reason you are using a DataSubscriber instead of the PLCAddressSelectColor2 and PLCAddressSelectColor3 of the BasicIndicator?

If you need to use the DataSubscriber, a better way to do this is to set Color1 to Yellow and Color2 to Blue. Then in the DataSubscriber set SelectColor2 and SelectColor3 to switch between the colors.

But overall, it looks like your code should work. I would try a break point in the routine to see if the event is firing. If so, then step through the code.
« Last Edit: January 13, 2025, 04:57:20 PM by Archie »

texasdru92

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Monitor different tags with DataSubscriber2 help
« Reply #2 on: January 13, 2025, 09:24:26 PM »
Thanks for the reply @Archie. I'm using DataSubscriber for this because I want to add more states (colors) such as divert active, divert disabled, divert 50% full, divert 100% full, and divert jam.. and maybe more  ;D. I thought using DataSubscribers with BasicIndicators was the way to achieve this. I believe I fixed it by changing the scope of divert status variables. It seems to be working with all the diverts being full, but I'm connecting to my system through a VPN so its pretty slow, I'll check it when I'm on-site tomorrow.

Here is the updated code:
Code: [Select]

    Private d5_full As Boolean = False
    Private d5_half_full As Boolean = False
    Private d5_active As Boolean = False

    Private Sub Divert5_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs)

        If e.PlcAddress = "SORT_LANE5_FULL_TIMER.DN" Then
            If e.Values(0) = True Then
                d5_full = True
            End If
        End If

        If e.PlcAddress = "SORT_LANE5_ACTIVE" Then
            If e.Values(0) = True Then
                d5_active = True
            End If
        End If

        If e.PlcAddress = "SORT_LANE5_HALF_FULL_TIMER.DN" Then
            If e.Values(0) = True Then
                d5_half_full = True
            End If
        End If

        If d5_active And Not d5_half_full And Not d5_full Then
            Divert_5.Color1 = Color.Green
        ElseIf d5_active And d5_full And d5_half_full Then
            Divert_5.Color1 = Color.Blue
        ElseIf d5_active And Not d5_full And d5_half_full Then
            Divert_5.Color1 = Color.Yellow
        End If



    End Sub
« Last Edit: January 13, 2025, 09:26:50 PM by texasdru92 »