AdvancedHMI Software
General Category => Support Questions => Topic started by: ScottN 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.
-
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:
m_synchronizationContext = System.Windows.Forms.WindowsFormsSynchronizationContext.Current
with m_synchronizingContext set to Nothing, no callback will be pushed onto the UI thread.
-
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
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)
-
I tried this on version 3.99y Beta 19 and not getting any exception:
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?
-
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?
-
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.
-
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.
-
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,
-
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,