Author Topic: Checking different members of a datasubscriber  (Read 4171 times)

paintman

  • Newbie
  • *
  • Posts: 17
    • View Profile
Checking different members of a datasubscriber
« on: June 27, 2024, 03:06:33 PM »
Hello,
I am using Datasubcriber2 to check 8 different bits, but i think i may be calling the values wrong. Other examples i have seen are only calling on one bit at a time.
This is a snippet of my code:
Code: [Select]
        If e.Values(0) = True Then
            shutcut.Value = initial0 + 1
        End If
        If e.Values(1) = True Then
            sc_call.Value = initial1 + 1
        End If
        If e.Values(2) = True Then
            boxpos.Value = initial2 + 1
        End If
        If e.Values(3) = True Then
            boxblock.Value = initial3 + 1
        End If
        If e.Values(4) = True Then
            loomguard.Value = initial4 + 1
        End If
        If e.Values(5) = True Then
            mispick.Value = initial5 + 1
        End If
        If e.Values(6) = True Then
            patalarm.Value = initial6 + 1
        End If
        If e.Values(7) = True Then
            tension.Value = initial7 + 1
        End If

The error i get is for e.Values(1), which says 'Index was out of range. Must be non-negative and less than the size of the collection.' but i cam calling member 1 of the datasubscriber right?

I may be doing this wrong, which is why i am asking.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Checking different members of a datasubscriber
« Reply #1 on: June 27, 2024, 04:14:54 PM »
If you have 8 addresses in PLCAddressValueItems that are not an array, the DataReturned event will fire 8 different times. To know what address the value is returned for check e.PLCAddress

paintman

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Checking different members of a datasubscriber
« Reply #2 on: June 28, 2024, 10:10:13 AM »
So, I specified the PLCAddress on the the PLCAddressValueItems for each member. Will I need to define that in the code as well?

If so would it just be the same structure just like this?

Code: [Select]
        If e.PLCAddres = "B18:0/1" Then
            shutcut.Value = initial0 + 1
        End If

I was hoping to be able to check each individual member for a T/F statement to add the values

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Checking different members of a datasubscriber
« Reply #3 on: June 28, 2024, 10:33:47 AM »
You also need to check the value
Code: [Select]
        If string.compare(e.PLCAddres,"B18:0/1",True)=0 AndAlso string.compare(e.Values(0),"True",True)=0 Then
            shutcut.Value = initial0 + 1
        End If
[code]

paintman

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Checking different members of a datasubscriber
« Reply #4 on: June 28, 2024, 12:56:09 PM »
Will the e.Value always remain as e.Value(0) or will it move to e.Value(1) in correspondence with the member values?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Checking different members of a datasubscriber
« Reply #5 on: June 28, 2024, 06:15:57 PM »
It will always be in the zero element. Sounds like you will need to store the values until all have been received then do your addition.