Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the server is actively disconnected(当服务器端主动断开时) #74

Open
jkh404 opened this issue Jan 25, 2022 · 2 comments
Open

Comments

@jkh404
Copy link

jkh404 commented Jan 25, 2022

我用的EasyModbusTCP.NET v5.6
当TCP服务器断开连接时,客户端并不能获取到反馈,依然能够读取和写入(显然这是错误的)。
不过,我查看EasyModbusTCP.NET 项目的 ModbusClient.cs 源代码后, 将Connected的代码改为以下代码即可得到正确的反馈。

public bool Connected
{
	get{
                if (serialport != null)
                {
                    return (serialport.IsOpen);
                }

                if (udpFlag & tcpClient != null)
                    return true;
                if (tcpClient == null)
                    return false;
                else
                {
                    return connected && tcpClient.Connected;

                }

	}
}

image
也许这不是最好的处理方法,但经过我的测试确实解决了这个问题。哈哈😁
en:
I use EasyModbusTCP.NET v5.6
When the TCP server is disconnected, the client cannot get feedback and can still read and write (obviously wrong).
However, after I looked at the ModbusClient.cs source code of the EasyModbusTCP.NET project, I changed the Connected code to the following code to get the correct feedback.
Maybe this is not the best way to deal with it, but my tests did solve the problem.😁

@jkh404
Copy link
Author

jkh404 commented Jan 25, 2022

这是最终效果
QQ录屏20220125125504

@wmx1033
Copy link

wmx1033 commented Mar 7, 2024

的确实现了,顶一个

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants