AdvancedHMI Software

General Category => Support Questions => Topic started by: paintman on June 27, 2024, 03:06:33 PM

Title: Checking different members of a datasubscriber
Post by: paintman 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.
Title: Re: Checking different members of a datasubscriber
Post by: Archie 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
Title: Re: Checking different members of a datasubscriber
Post by: paintman 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
Title: Re: Checking different members of a datasubscriber
Post by: Archie 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]
Title: Re: Checking different members of a datasubscriber
Post by: paintman 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?
Title: Re: Checking different members of a datasubscriber
Post by: Archie 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.