基本信息
源码名称:modbus tcp 服务器接口(支持多个客户端进行连接)
源码大小:11.75M
文件格式:.zip
开发语言:C#
更新时间:2020-07-24
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 4 元 
   源码介绍

基于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);
            }