Author Topic: DataSubscriber2 Array Value issues  (Read 352 times)

timryder

  • Jr. Member
  • **
  • Posts: 83
  • Still trying to figure it out
    • View Profile
DataSubscriber2 Array Value issues
« on: July 07, 2023, 11:41:20 AM »
I noticed today that in the DataSubscriber2 object, when returning an Array of "Word" from a Micro800 series plc I get some really weird behaviors depending on the configuration.

In the first sceanario, I created individual entries in the DS2 control for each member of the Array, but interestingly enough, only the first instance of "Data_To_DC_PLC.Analog_Input[0]" fires within my ElseIf structure...

Code: [Select]
If e.Values IsNot Nothing And e.ErrorId = 0 Then
                SSB.Connected = True    'Set the Property to show connected.
                If e.PlcAddress = "Data_To_DC_PLC.DigitalInputs" Then
                    UpdateInputs(e.Values(0))
                ElseIf e.PlcAddress = "Data_From_DC_PLC[0]" Then
                    UpdateOutputs(e.Values(0))
                ElseIf e.PlcAddress = "Data_To_DC_PLC.Analog_Input[0]" Then
                    UpdateAnalog(0, e.Values(0))
                ElseIf e.PlcAddress = "Data_To_DC_PLC.Analog_Input[1]" Then
                    UpdateAnalog(1, e.Values(0))
                ElseIf e.PlcAddress = "Data_To_DC_PLC.Analog_Input[2]" Then
                    UpdateAnalog(2, e.Values(0))
                ElseIf e.PlcAddress = "Data_To_DC_PLC.Analog_Input[3]" Then
                    UpdateAnalog(3, e.Values(0))
                End If
            End If

So yeah strangely enough when I put breakpoints on the remaining ElseIf cases, they never fire.

When I set the Address to "Data_To_DC_PLC.Analog_Input" and then the NumberOfElements to 4, that's when it gets really strange. The ElseIf without the Array pointer 0 does fire, but the values returned have a count of 4 and only the first index actually has a value. The remaining 3 all say "Nothing"... (See attached). 

I have implemented a fix for this in my own code, but i don't quite understand why this is. The Raw Values actually have 2 bytes worth of data for each Tag and using that I am able to convert them into Int16 which gets me my values. But clearly something is broken and it isn't evaluating the raw data for subsequent members of an array properly.

Code: [Select]
If e.Values IsNot Nothing And e.ErrorId = 0 Then
                SSB.Connected = True    'Set the Property to show connected.
                If e.PlcAddress = "Data_To_DC_PLC.DigitalInputs" Then
                    UpdateInputs(e.Values(0))
                ElseIf e.PlcAddress = "Data_From_DC_PLC[0]" Then
                    UpdateOutputs(e.Values(0))
                ElseIf e.PlcAddress = "Data_To_DC_PLC.Analog_Input" Then
                    Dim i As Integer = BitConverter.ToInt16(e.RawData, 6)
                    UpdateAnalog(0, i)
                    i = BitConverter.ToInt16(e.RawData, 8)
                    UpdateAnalog(1, i)
                    i = BitConverter.ToInt16(e.RawData, 10)
                    UpdateAnalog(2, i)
                    i = BitConverter.ToInt16(e.RawData, 12)
                    UpdateAnalog(3, i)
                End If
            End If

Still just trying to figure out this thing called Life.