Author Topic: ModbusBase OnComError - InvalidOperationException  (Read 3066 times)

andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
ModbusBase OnComError - InvalidOperationException
« on: October 07, 2015, 01:33:34 AM »
I am using V399a, got error when pressing BasicButton while Modbus comm not established.
The BasicButton has the following script to reset value after releasing the click:
Code: [Select]
Private Sub OPEN_BTN_MouseUp(sender As Object, e As EventArgs) Handles OPEN_BTN.MouseUp
        Try
            ModbusTCPCom1.Write(OPEN_BTN.PLCAddressClick, "0")
        Catch ex As Exception

        End Try
    End Sub

Already put try catch statement, but if I click the BasicButton few times,
the application will become slow, then InvalidOperationException occurs (refer to attachment).
Please advise regarding this, Thank you.

Best regards,
Andrew

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusBase OnComError - InvalidOperationException
« Reply #1 on: October 07, 2015, 01:43:53 AM »
Add this conditional statement:

            If DirectCast(m_SynchronizingObject, System.Windows.Forms.Control).IsHandleCreated Then
                m_SynchronizingObject.BeginInvoke(errorsd, Parameters)
            End If

andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: ModbusBase OnComError - InvalidOperationException
« Reply #2 on: October 07, 2015, 02:10:43 AM »
Add this conditional statement:

            If DirectCast(m_SynchronizingObject, System.Windows.Forms.Control).IsHandleCreated Then
                m_SynchronizingObject.BeginInvoke(errorsd, Parameters)
            End If
Doing few times testing with above code, result: no more error, thanks a lot.

But still if I click the BasicButton multiple times, the application becomes slow.
It seems like the click event is "queuing", as I can see the BasicButton animation when it is pressed.
For example, I click 4 times, then the application becomes slow for about 4-6 seconds,
after the BasicButton changing state 4 times, then the application runs back to normal.
More click will take longer period of the slow performance.
Please help to advise, thank you.

Best regards,
Andrew

andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: ModbusBase OnComError - InvalidOperationException
« Reply #3 on: October 07, 2015, 03:06:27 AM »
If I'm not wrong, the older version doesn't have this slow performance problem.
Because I was often testing without connecting to PLC.
Suspecting the application becomes slow due to communication checking?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusBase OnComError - InvalidOperationException
« Reply #4 on: October 07, 2015, 09:49:42 PM »
What you are seeing is that the newer version writes synchronously, so the screen will become unresponsive while waiting on the device to acknowledge the write. This is necessary because the buffer can be overflowed with writes when the controller doesn't respond or responds very slow. Or more commonly if a lot of writes are done in code, asynchronous writing would very quickly fill the queue and throw exceptions.

andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: ModbusBase OnComError - InvalidOperationException
« Reply #5 on: October 07, 2015, 09:58:01 PM »
What you are seeing is that the newer version writes synchronously, so the screen will become unresponsive while waiting on the device to acknowledge the write. This is necessary because the buffer can be overflowed with writes when the controller doesn't respond or responds very slow. Or more commonly if a lot of writes are done in code, asynchronous writing would very quickly fill the queue and throw exceptions.

Ok, in this case I need to do something when communication with PLC is not established.
I cannot let user wondering why the HMI is unresponsive for such a long period.

Can you advise some codes to detect if ModbusTCPCom is available?
I will put condition with this in every button so that it prevents writing while no communication.
Thank you.

Best regards,
Andrew

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusBase OnComError - InvalidOperationException
« Reply #6 on: October 07, 2015, 10:36:55 PM »
I will make sure in the next version that ModbusTCPCom has ConnectionEstablished and ConnectionClosed events

andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: ModbusBase OnComError - InvalidOperationException
« Reply #7 on: October 07, 2015, 10:38:42 PM »
I will make sure in the next version that ModbusTCPCom has ConnectionEstablished and ConnectionClosed events

Looking forward, Thank you very much