Menu

ModbusClient.Connected property does not work

Rob
2015-03-18
2018-09-23
  • Rob

    Rob - 2015-03-18

    When I run a sample application like this:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using EasyModbus;
    
    namespace TestGui
    {
        public partial class Form1 : Form
        {
            public ModbusClient m;
    
            public Form1()
            {
                InitializeComponent();
                m = new ModbusClient();
                m.IPAddress = "172.17.6.23";
                m.Port = 502;
                m.Connect();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                m.Connected.ToString();
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                var r = m.ReadCoils(0, 1);
            }
        }
    }
    

    The Connected property always returns false, no matter if I check it right after .Connect() or even when I just read some data from my modbus device like in the button2_Click method above. Tested with version 1.0.5555.26938.

     
  • Rossmann Engineering

    You are right. I just fixed it.

    Thank you!

     
  • Bruno

    Bruno - 2015-05-06

    Hello, I had the same problem when using the property attached, could you solve it?

     
    • Rossmann Engineering

      The problem above has been fixed. I just tried it, and it is working.

      Did you use the latest Version (V1.5) ?

       
  • Bruno

    Bruno - 2015-05-08

    No, where I can download it?

     
  • Bruno

    Bruno - 2015-05-08

    It works! but is there any way to detect if the physical connection is established? because when I disconnect, I get an exception when using the connect property ..
    from now, thank you very much

     
  • Andrey

    Andrey - 2018-08-27

    Hi! Can I any case detect in Modbus client (C#) connection is established.
    While I disconnect MB server Modbus client steel retyrn some data, and conected property is "TRUE"
    version of EasyMB - 5.0
    TRhanks!

     

    Last edit: Andrey 2018-08-27
    • Rossmann Engineering

      Hi, unfortunately the "Connected" Property isn't 100% reliable. If the Server closes the connection, the "Connected" Property is still "TRUE". If you are trying to send a requets, in that case you would get an Timeout Exception.

      Propably the "Available" Method could be helpful. That Method checks only if the Server can be pinged via Network, but not if the connection is still alive.

       

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.