Author Topic: Datasubscriber2 and NumberOfElements  (Read 2287 times)

bobobo

  • Newbie
  • *
  • Posts: 19
    • View Profile
Datasubscriber2 and NumberOfElements
« on: October 07, 2015, 11:47:52 AM »
Hi
Is the NumberOfElements property in Collection of PLCAddressValueItems meant to enable subscription to an array?

I tried, but couldn't get it to work.

I am using Twincat driver and try to subscribe an array of 8 bools in the plc.

Since Twincat stores bools as bytes I tried to set number of elements both to 8 and 64, but i only get the DataChanged event when the first bool is changing, and the e.values is always count=1.

Maybe the feature is not programmed in Adv.HMI yet? I am using 3.99a

Best Regards


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Datasubscriber2 and NumberOfElements
« Reply #1 on: October 07, 2015, 12:06:56 PM »
The NumberOfElements for subscriptions is not currently supported on the TwinCAT driver. Right now only CLX and Omron drivers support it.

bobobo

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Datasubscriber2 and NumberOfElements
« Reply #2 on: October 08, 2015, 05:59:40 AM »
I made an attemt to add the function in a ugly work-around way...
In Datasubscriber2:
Code: [Select]
                    '* We must pass the address as a property name so the subscriptionHandler doesn't confuse the next address as a change for the same property
                    If m_PLCAddressValueItems(index).NumberOfElements <= 1 Then
                        SubScriptions.SubscribeTo(m_PLCAddressValueItems(index).PLCAddress, AddressOf PolledDataReturned, m_PLCAddressValueItems(index).PLCAddress)
                    Else
                        For element = 1 To m_PLCAddressValueItems(index).NumberOfElements
                            SubScriptions.SubscribeTo(m_PLCAddressValueItems(index).PLCAddress & "[" & element & "]", AddressOf PolledDataReturned, m_PLCAddressValueItems(index).PLCAddress & "[" & element & "]")
                        Next
                    End If

But it doesn't work.

However, if I manually add all elements of the variable (Alarm.Temperr[1], Alarm.TempErr[2], etc] in the datasubscriber, I can use this in the datachanged event:
Code: [Select]
        Select Case e.PlcAddress.Split("[")(0)
            Case "ALARM.TEMPERR"
                AlarmNum = e.PlcAddress.Split("[")(1).Trim(New Char() {"[", "]"}) - 1)
                State = e.Values(0)
                     ...
        End Select

Would have been nice if the NumberOfElements were implemented....

Do you have suggestions of better ways to imlement this outside the closed dll? in subscription handler?
The subscription handler looked too advanced for me, that's why i tried to put it in DataSubscriber2

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Datasubscriber2 and NumberOfElements
« Reply #3 on: October 08, 2015, 08:14:03 AM »
It would all be implemented in TwinCAT.vb in the Subscribing region. It gets quite complicated because you have to account for optimizing where it would put multiple subscriptions to different elements in the same array read. It also has to account for packet sizes and sum up reads. It's quite time consuming and can easily break the driver, hence the reason it has been only implemented in a couple drivers so far.

We will eventually implement, but I just don't know when since we have never needed it for out internal projects. The unfortunate thing with the TwinCAT driver is that it has such a limited user base since it cannot communicate with TwinCAT on the same machine. If Beckhoff would ever come off the "proprietary" technique of communicating with their router without using their DLLs, I'm sure AdvancedHMI would become much more widely used in the TwinCAT user community.