Author Topic: How CreateGroupedReadList to Adress MX000 AND DW000 PX000  (Read 686 times)

abdala

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
How CreateGroupedReadList to Adress MX000 AND DW000 PX000
« on: May 23, 2017, 01:29:51 AM »
How CreateGroupedReadList to Adress MX000 AND DW000 PX000

and max adress 16 bloek type


I,m using sours code modbus rtu the projact xgt ls


Code: [Select]
   Private Sub CreateGroupedReadList()
            SyncLock (SubscriptionLock)
                GroupedSubscriptionReads.Clear()
                SubscriptionListChanged = False

                Dim index, ItemCountToGroup, HighestElement, ElementSpan As Integer


                While index < SubscriptionList.Count
                    Try
                        '* optimize in as few reads as possible - try group reading
                        '* and perform in Async Mode
                        ItemCountToGroup = 0
                        ElementSpan = HighestElement - SubscriptionList(index).Address.Element
                        While (index + ItemCountToGroup + 1) < SubscriptionList.Count AndAlso
                            SubscriptionList(index + ItemCountToGroup).Address.ReadFunctionCode = SubscriptionList(index + ItemCountToGroup + 1).Address.ReadFunctionCode AndAlso
                            SubscriptionList(index + ItemCountToGroup).Address.BitsPerElement = SubscriptionList(index + ItemCountToGroup + 1).Address.BitsPerElement AndAlso
                            ((SubscriptionList(index + ItemCountToGroup + 1).Address.Element + SubscriptionList(index + ItemCountToGroup + 1).Address.NumberOfElements) - SubscriptionList(index).Address.Element) < m_MaxReadGroupSize AndAlso
                            SubscriptionList(index + ItemCountToGroup).Address.Address.ToUpper = SubscriptionList(index + ItemCountToGroup + 1).Address.Address.ToUpper

                            ItemCountToGroup += 1
                        End While
                    Catch ex As Exception
                        Throw
                    End Try

                    ElementSpan = (SubscriptionList(index + ItemCountToGroup).Address.Element - SubscriptionList(index).Address.Element)
                    '* Correct is the last element is a 32 bit read
                    If SubscriptionList(index + ItemCountToGroup).Address.BitsPerElement > 16 Then
                        ElementSpan += CInt(SubscriptionList(index + ItemCountToGroup).Address.BitsPerElement / 8) - 1
                    End If

                    Dim sr As New SubscriptionRead
                    sr.Address = SubscriptionList(index).Address.Address
                    '* Are we using a single bit from an integer?
                    If SubscriptionList(index).Address.BitNumber >= 0 Then
                        '* If so, then only subscribe to the word
                        If SubscriptionList(index).Address.Address.LastIndexOf(".") > 0 Then
                            sr.Address = SubscriptionList(index).Address.Address.Substring(0, SubscriptionList(index).Address.Address.LastIndexOf("."))
                        End If
                    End If
                    sr.NumberToRead = (ElementSpan + 1)

                    GroupedSubscriptionReads.Add(sr)
                    index += (1 + ItemCountToGroup)
                End While
            End SyncLock
        End Sub





plasee help
« Last Edit: May 23, 2017, 01:33:21 AM by abdala »