Author Topic: How to Manage modbusRTUCom connection  (Read 1070 times)

mesutonus

  • Newbie
  • *
  • Posts: 13
    • View Profile
How to Manage modbusRTUCom connection
« on: March 17, 2015, 04:30:16 PM »
Hello,

when calling read/write functions from ModbusRTUCom object it connects automatically. However i can not manage connection and close the port it opens.   
Could you please help?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5268
    • View Profile
    • AdvancedHMI
Re: How to Manage modbusRTUCom connection
« Reply #1 on: March 17, 2015, 04:41:48 PM »
You could dispose the instance, but then it is no longer usable.

ModbusRTUCom1.Dispose

What would be a scenario where you would need to close the connection without exiting the application?

mesutonus

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: How to Manage modbusRTUCom connection
« Reply #2 on: March 17, 2015, 04:44:14 PM »
I use System.IO.SerialPort object  to write registers. And reading with advancedhmi.
So i need to keep only only object  alive during process.

mesutonus

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: How to Manage modbusRTUCom connection
« Reply #3 on: March 17, 2015, 04:47:10 PM »
After a short brainstorm it seemed impossible to manage. Because readings and writings are being made in short frequencies. So a reading request may interrupt an important write process.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5268
    • View Profile
    • AdvancedHMI
Re: How to Manage modbusRTUCom connection
« Reply #4 on: March 17, 2015, 04:48:53 PM »
You can add this subroutine to ModbusRTUCom.VB

        Public Sub CloseConnection()
            If DLL.ContainsKey(MyDLLInstance) AndAlso DLL(MyDLLInstance) IsNot Nothing Then
                DLL(MyDLLInstance).CloseCom()
            End If
        End Sub

mesutonus

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: How to Manage modbusRTUCom connection
« Reply #5 on: March 17, 2015, 04:49:44 PM »
great!