嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 4 元微信扫码支付:4 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
基于modbus tcp协议下的tcp接口,可以使用多个客户端进行连接
//判断端口合法性
if (!int.TryParse(textBox2.Text, out int port))
{
MessageBox.Show("端口输入不正确!");
return;
}
try
{
if (zhi == 0)
{
busTcpServer = new HslCommunication.ModBus.ModbusTcpServer();//实例化一个Modubs TCP服务器
busTcpServer.LogNet = new HslCommunication.LogNet.LogNetSingle("logs.txt");//创建日志文件
busTcpServer.LogNet.BeforeSaveToFile = LogNet_BeforeSaveToFile;
busTcpServer.OnDataReceived = BusTcpServer_OnDataReceived;
busTcpServer.ServerStart(port);//根据接口启动服务器
button1.Text = "点击关闭";
button1.BackColor = Color.LimeGreen;
button4.Text = "正在运行";
button4.BackColor = Color.LimeGreen;
timer1.Enabled = true;
timer2.Enabled = true;
zhi = 1;
}
else if (zhi == 1)
{
DialogResult result = MessageBox.Show("你确定要关闭?", "退出提示", MessageBoxButtons.OKCancel);
if (result.ToString() == "Cancel")
{
return;
}
else if (result.ToString() == "OK")
{
busTcpServer.ServerClose();
button1.Text = "点击运行";
button1.BackColor = Color.Transparent;
button4.Text = "停止运行";
button4.BackColor = Color.Transparent;
timer1.Enabled = false;
timer2.Enabled = false;
progressBar1.Value = 0;
progressBar1.BackColor = Color.Red;
progressBar2.Value = 0;
progressBar2.BackColor = Color.Red;
zhi = 0;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}