You already have a working solution, 2 instances of DataSubscriber2, so all this is just an attempt to find out what was causing the issue you had.
Your code will not work properly with subscriptions as I suggested in the previous post.
When these subscriptions are grouped then only the first address is reported back.
Here is an example of VB code to find out what value changed when subscribed within DataSubscriber2 to address 30001 with 3 elements:
Private previousValue As System.Collections.ObjectModel.Collection(Of String)
Private previousValueSet As Boolean
Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
If e.ErrorId = 0 Then
'Values returned for addresses: 30001, 30002, 30003
If e.PlcAddress = "30001" Then
If previousValueSet Then
For i As Integer = 0 To e.Values.Count - 1
If previousValue(i) <> e.Values(i) Then
If i = 0 Then 'Address: 30001
MessageBox.Show("Value of address 30001 has changed from " & previousValue(i) & " to " & e.Values(i))
'Do something that this change triggers
ElseIf i = 1 Then 'Address: 30002
MessageBox.Show("Value of address 30002 has changed from " & previousValue(i) & " to " & e.Values(i))
'Do something that this change triggers
Else 'Address: 30003
MessageBox.Show("Value of address 30003 has changed from " & previousValue(i) & " to " & e.Values(i))
'Do something that this change triggers
End If
previousValue(i) = e.Values(i)
End If
Next
Else
'Initial read
previousValue = e.Values
previousValueSet = True
End If
End If
End If
End Sub
Or maybe slightly different:
Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
If e.ErrorId = 0 Then
'Values returned for addresses: 30001, 30002, 30003
If e.PlcAddress = "30001" Then
If previousValueSet Then
For i As Integer = 0 To e.Values.Count - 1
If previousValue(i) <> e.Values(i) Then
MessageBox.Show("Value of address " & (CInt(e.PlcAddress) + i) & " has changed from " & previousValue(i) & " to " & e.Values(i))
'Do something that this change triggers by using 'CInt(e.PlcAddress) + i' as a condition in your code
previousValue(i) = e.Values(i)
End If
Next
Else
'Initial read
previousValue = e.Values
previousValueSet = True
End If
End If
End If
End Sub
In case if 00000 registers are added, one might consider padding the address in the message:
Private previousValues00001 As System.Collections.ObjectModel.Collection(Of String)
Private previousValues30001 As System.Collections.ObjectModel.Collection(Of String)
Private previousValues00001Set As Boolean
Private previousValues30001Set As Boolean
Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
If e.ErrorId = 0 Then
'Values returned for addresses: 00001 to 00010
If e.PlcAddress = "00001" Then
If previousValues00001Set Then
For i As Integer = 0 To e.Values.Count - 1
If previousValues00001(i) <> e.Values(i) Then
MessageBox.Show("Value of address " & (CInt(e.PlcAddress) + i).ToString.PadLeft(5, "0"c) & " has changed from " & previousValues00001(i) & " to " & e.Values(i))
'Do something that this change triggers by using 'CInt(e.PlcAddress) + i' as a condition in your code
previousValues00001(i) = e.Values(i)
End If
Next
Else
'Initial read
previousValues00001 = e.Values
previousValues00001Set = True
End If
ElseIf e.PlcAddress = "30001" Then
'Values returned for addresses: 30001 to 30003
If previousValues30001Set Then
For i As Integer = 0 To e.Values.Count - 1
If previousValues30001(i) <> e.Values(i) Then
MessageBox.Show("Value of address " & (CInt(e.PlcAddress) + i) & " has changed from " & previousValues30001(i) & " to " & e.Values(i))
'Do something that this change triggers by using 'CInt(e.PlcAddress) + i' as a condition in your code
previousValues30001(i) = e.Values(i)
End If
Next
Else
'Initial read
previousValues30001 = e.Values
previousValues30001Set = True
End If
End If
End If
End Sub