Author Topic: EthernetIPforCLXCom Data Subscription in a different thread.  (Read 1188 times)

ScottN

  • Newbie
  • *
  • Posts: 6
    • View Profile
EthernetIPforCLXCom Data Subscription in a different thread.
« on: February 17, 2019, 05:37:49 PM »
I currently have a Windows Forms application using AdvancedHMI and want the subscription callback to be executed on a different thread to the UI. This is because I have a few UI operations that are blocking the callback. Any help would be greatly appreciated.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLXCom Data Subscription in a different thread.
« Reply #1 on: February 17, 2019, 06:39:50 PM »
There are a few ways to go about this. The first would be to instantiate the driver in code and use the class MfgControl.AdvancedHMI.Drivers.EthernetIPforCLX. This goes below the Winforms layer where events and callbacks do not synchronize with the UI thread. It will then be up to you to do any invoking onto the UI thread.

Another option is to modify EthernetIPforCLXCom.vb and comment out this line of code:
Code: [Select]
        m_synchronizationContext = System.Windows.Forms.WindowsFormsSynchronizationContext.Current
with m_synchronizingContext set to Nothing, no callback will be pushed onto the UI thread.

ScottN

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: EthernetIPforCLXCom Data Subscription in a different thread.
« Reply #2 on: February 17, 2019, 07:07:03 PM »
Thanks for your response. I tried to use the class MfgControl.AdvancedHMI.Drivers.EthernetIPforCLX but when I tried to write to a tag I got a NullReference Exception at
Code: [Select]
   at MfgControl.AdvancedHMI.Drivers.CIP.CIPforCLX.a(CLXAddress A_0, Int64 A_1, Int32 A_2)
   at MfgControl.AdvancedHMI.Drivers.CIP.CIPforCLX.a(CLXAddress A_0, String[] A_1, Int32 A_2, Int32 A_3, Int64 A_4)
   at MfgControl.AdvancedHMI.Drivers.EthernetIPforCLX.BeginWrite(String startAddress, Int32 numberOfElements, String[] dataToWrite)
   at MfgControl.AdvancedHMI.Drivers.EthernetIPforCLX.Write(String startAddress, Int32 numberOfElements, String[] dataToWrite)
   at MfgControl.AdvancedHMI.Drivers.EthernetIPforCLX.Write(String startAddress, Int32 dataToWrite)
« Last Edit: February 17, 2019, 07:10:30 PM by ScottN »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLXCom Data Subscription in a different thread.
« Reply #3 on: February 17, 2019, 07:45:48 PM »
I tried this on version 3.99y Beta 19 and not getting any exception:
Code: [Select]
        Dim drv As New MfgControl.AdvancedHMI.Drivers.EthernetIPforCLX
        drv.IPAddress = "192.168.0.1"
        drv.Write("MyTag", "1")
I don't have a real PLC at hand right now, so I got a timeout. What version of AdvancedHMI are you using?

ScottN

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: EthernetIPforCLXCom Data Subscription in a different thread.
« Reply #4 on: February 17, 2019, 07:54:33 PM »
Sorry, that is working for me now I just rebuilt the solution. However, the ConnectionEstablished event is not firing now. Is that expected or am I doing something wrong?

ScottN

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: EthernetIPforCLXCom Data Subscription in a different thread.
« Reply #5 on: February 17, 2019, 08:12:52 PM »
Ah, so if I try a write straight after creating the EthernetIPforCLX instance it then add a handler to the ConnectionEstablished event it doesn't fire. However, if I add a ConnectionEstablished event handler and inside the handler I try a write I get the NullReferenceException shown below.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLXCom Data Subscription in a different thread.
« Reply #6 on: February 24, 2019, 05:13:24 PM »
Ah, so if I try a write straight after creating the EthernetIPforCLX instance it then add a handler to the ConnectionEstablished event it doesn't fire. However, if I add a ConnectionEstablished event handler and inside the handler I try a write I get the NullReferenceException shown below.
This is being fixed in the next update. Out of curiosity why are you waiting for the ConnectionEstablished event to do the write. If the driver is not connected and a write is done, it will connect automatically.

ScottN

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: EthernetIPforCLXCom Data Subscription in a different thread.
« Reply #7 on: February 24, 2019, 05:18:04 PM »
I realised I didn't need to do the write in the ConnectionEstablished event so I moved it elsewhere and it's working. I haven't been able to test much recently but the most recent bug I have is that I am getting the same tag simultaneously in the Callback in two different threads.

Like I said, I haven't looked into it much so it could be my code that's the problem but if it's a known issue let me know.

Cheers,

ScottN

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: EthernetIPforCLXCom Data Subscription in a different thread.
« Reply #8 on: February 24, 2019, 11:16:14 PM »
Hi,

Slightly different problem now but I cannot seem to read a tag during the SubscriptionDataReceived event. I get the error No response from PLC. I'm using driver 3.99x also. Is this also a known bug?

Cheers,