Author Topic: Modbus dataSubscriber and NumberOfElements  (Read 1191 times)

czubak_p

  • Newbie
  • *
  • Posts: 3
    • View Profile
Modbus dataSubscriber and NumberOfElements
« on: January 20, 2021, 01:58:23 PM »
Is NumberOfElements property supported in Modbus DataSubcriber component, because I set to more than 1 but in dataSubscriber1_DataReturned event always SubscribedValues collection return only one element

Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: Modbus dataSubscriber and NumberOfElements
« Reply #1 on: January 20, 2021, 03:50:26 PM »
You should be using DataSubcriber2 instead of DataSubcriber.

czubak_p

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Modbus dataSubscriber and NumberOfElements
« Reply #2 on: February 02, 2021, 03:34:45 PM »
thanks, it works

czubak_p

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Modbus dataSubscriber and NumberOfElements
« Reply #3 on: February 03, 2021, 03:56:00 PM »
sorry, i hurried up that it works
If we create a new project and give it only the DataSubscriber2 component, one element in the items collection, no matter how much we set in NoOfElements, the query always goes for one element in the modbus frame and we get one element in the DataReturned event.
If we add any control in the project, with an address close to the previous one, so that the query is optimized, and both addresses are polled in one frame, then in DataReturned we will get as many elements as are actually set in NoOfElements, but if optimization does not occur because the addresses are too far apart, we will not get so many elements again.

Godra

  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: Modbus dataSubscriber and NumberOfElements
« Reply #4 on: February 03, 2021, 06:01:08 PM »
Check the attached pictures for the quick setup I did with ModbusTCP driver, DataSubscriber2 and a label to show values.

There is 5 values returned and they are like this: e.Values(0) to e.Values(4).

This is the code used:

Code: [Select]
    Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
        If e.Values.Count > 0 Then
            Label9.Text = "Values:"
            For i = 0 To e.Values.Count - 1
                Label9.Text &= " " & e.Values(i)
            Next
        End If
    End Sub


Are you doing this correctly?