Esempio n. 1
0
        public async Task StartAsync()
        {
            ModBusTcpServer server = new ModBusTcpServer(int.Parse("LocalPort".GetConfig()));

            server.Start();

            await Task.Delay(1000 * 1000);
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            ModBusTcpServer server = new ModBusTcpServer("127.0.0.1", 502);

            server.Start();
            button1.Text     = "模拟服务已启动";
            button1.Enabled  = false;
            but_open.Enabled = true;
        }
Esempio n. 3
0
        public async Task StartAsync()
        {
            var             RedisConnection = "RedisConnection".GetConfig();
            ModBusTcpServer server          = new ModBusTcpServer("LocalIP".GetConfig(), int.Parse("LocalPort".GetConfig()), RedisConnection);

            server.Start();

            await Task.Delay(1000 * 1000);
        }
Esempio n. 4
0
 private void button1_Click(object sender, EventArgs e)
 {
     server?.Stop();
     server = new ModBusTcpServer(502);
     server.Start();
     button1.Enabled = false;
     button2.Enabled = true;
     txt_content.AppendText($"[{DateTime.Now.ToLongTimeString()}]开启仿真模拟服务\r\n");
 }
Esempio n. 5
0
 public DTSEquip()
 {
     channelInfo           = new List <ChannelInfos>();
     Channels              = new Dictionary <string, List <ChannelInfos> >();
     ChannelFiberBreakInfo = new Dictionary <string, List <FiberBreakInfo> >();
     ChannelRegistData     = new Dictionary <string, List <RegistData> >();
     tcpServer             = new ModBusTcpServer();
     _isRunning            = false;
     tcpServer.equipnum    = DTSNum;
     obj  = new object();
     obj1 = new object();
 }
Esempio n. 6
0
 private void userButton1_Click(object sender, EventArgs e)
 {
     if (!m_IsModBusStart)
     {
         m_IsModBusStart           = true;
         tcpServer                 = new ModBusTcpServer();                                                                // 实例化服务器接收对象
         tcpServer.LogNet          = new HslCommunication.LogNet.LogNetSingle(Application.StartupPath + @"\Logs\log.txt"); // 设置日志文件
         tcpServer.OnDataReceived += TcpServer_OnDataReceived;                                                             // 关联数据接收方法
         tcpServer.ServerStart(51234);                                                                                     // 绑定端口
         timer.Start();                                                                                                    // 启动服务
     }
 }
Esempio n. 7
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         server?.Stop();
         server = new ModBusTcpServer(502);
         server.Start();
         button1.Enabled = false;
         button2.Enabled = true;
         AppendText($"开启仿真模拟服务");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 8
0
 private void userButton1_Click(object sender, EventArgs e)
 {
     if (int.TryParse(textBox1.Text, out int port))
     {
         tcpServer                 = new ModBusTcpServer();                                                                // 实例化服务器接收对象
         tcpServer.LogNet          = new HslCommunication.LogNet.LogNetSingle(Application.StartupPath + @"\Logs\log.txt"); // 设置日志文件
         tcpServer.OnDataReceived += TcpServer_OnDataReceived;                                                             // 关联数据接收方法
         tcpServer.ServerStart(port);                                                                                      // 绑定端口
         timer.Start();                                                                                                    // 启动服务
         textBox1.Enabled    = false;
         userButton1.Enabled = false;
     }
     else
     {
         MessageBox.Show("格式输入有误");
     }
 }
Esempio n. 9
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (server == null)
     {
         server = new ModBusTcpServer("127.0.0.1", 502);
     }
     if (button1.Text == "模拟从机")
     {
         server.Start();
         button1.Text = "模拟服务已启动";
     }
     else
     {
         server.Close();
         button1.Text = "模拟从机";
     }
 }
Esempio n. 10
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         if (txt_content.Text.Contains("小技巧"))
         {
             txt_content.Text = string.Empty;
         }
         server?.Stop();
         server = new ModBusTcpServer(502);
         server.Start();
         button1.Enabled = false;
         button2.Enabled = true;
         AppendText($"开启仿真模拟服务");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 11
0
        private void userButton1_Click(object sender, EventArgs e)
        {
            if (!m_IsModBusStart)
            {
                m_IsModBusStart           = true;
                tcpServer                 = new ModBusTcpServer();    // 实例化服务器接收对象
                tcpServer.LogNet          = busTcpClient.LogNet;      // 设置日志文件
                tcpServer.OnDataReceived += TcpServer_OnDataReceived; // 关联数据接收方法
                tcpServer.ServerStart(51234);                         // 绑定端口
                timer.Start();                                        // 启动服务

                // 创建一个数据订阅
                ModBusMonitorAddress monitorAddress = new ModBusMonitorAddress()
                {
                    Address = 0x02
                };
                monitorAddress.OnWrite  += MonitorAddress_OnWrite;
                monitorAddress.OnChange += MonitorAddress_OnChange;
                tcpServer.AddSubcription(monitorAddress);
            }
        }
Esempio n. 12
0
        private void userButton1_Click(object sender, EventArgs e)
        {
            if (!m_IsModBusStart)
            {
                m_IsModBusStart           = true;
                tcpServer                 = new ModBusTcpServer();                                                                // 实例化服务器接收对象
                tcpServer.LogNet          = new HslCommunication.LogNet.LogNetSingle(Application.StartupPath + @"\Logs\log.txt"); // 设置日志文件
                tcpServer.OnDataReceived += TcpServer_OnDataReceived;                                                             // 关联数据接收方法
                tcpServer.ServerStart(51234);                                                                                     // 绑定端口
                timer.Start();                                                                                                    // 启动服务

                // 创建一个数据订阅
                ModBusMonitorAddress monitorAddress = new ModBusMonitorAddress()
                {
                    Address = 0x01
                };
                monitorAddress.OnWrite  += MonitorAddress_OnWrite;
                monitorAddress.OnChange += MonitorAddress_OnChange;
                tcpServer.AddSubcription(monitorAddress);
            }
        }