예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show("端口输入不正确!");
                return;
            }


            try
            {
                busTcpServer        = new HslCommunication.ModBus.ModbusTcpServer( );                // 实例化对象
                busTcpServer.LogNet = new HslCommunication.LogNet.LogNetSingle("logs.txt");          // 配置日志信息
                busTcpServer.LogNet.BeforeSaveToFile += LogNet_BeforeSaveToFile;
                busTcpServer.OnDataReceived          += BusTcpServer_OnDataReceived;
                busTcpServer.ServerStart(port);

                button1.Enabled = false;
                panel2.Enabled  = true;
                button4.Enabled = true;

                timerSecond          = new System.Windows.Forms.Timer( );
                timerSecond.Interval = 1000;
                timerSecond.Tick    += TimerSecond_Tick;
                timerSecond.Start( );
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show("端口输入不正确!");
                return;
            }



            try
            {
                busTcpServer        = new HslCommunication.ModBus.ModbusTcpServer( );
                busTcpServer.LogNet = new HslCommunication.LogNet.LogNetSingle("logs.txt");
                busTcpServer.LogNet.BeforeSaveToFile += LogNet_BeforeSaveToFile;
                busTcpServer.OnDataReceived          += BusTcpServer_OnDataReceived;
                busTcpServer.ServerStart(port);

                button1.Enabled = false;
                panel2.Enabled  = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }

            try
            {
                busTcpServer = new HslCommunication.ModBus.ModbusTcpServer( );                       // 实例化对象
                busTcpServer.ActiveTimeSpan  = TimeSpan.FromHours(1);
                busTcpServer.OnDataReceived += BusTcpServer_OnDataReceived;

                // add some accounts
                busTcpServer.AddAccount("admin", "123456");
                busTcpServer.AddAccount("hsl", "test");

                ComboBox2_SelectedIndexChanged(null, new EventArgs( ));
                busTcpServer.IsStringReverse = checkBox3.Checked;

                userControlReadWriteServer1.SetReadWriteServer(busTcpServer, "100");
                busTcpServer.ServerStart(port);

                button1.Enabled  = false;
                panel2.Enabled   = true;
                button11.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #4
0
        private void BusTcpServer_OnDataReceived(HslCommunication.ModBus.ModbusTcpServer tcpServer, byte[] modbus)
        {
            if (!checkBox1.Checked)
            {
                return;
            }

            if (InvokeRequired)
            {
                BeginInvoke(new Action <HslCommunication.ModBus.ModbusTcpServer, byte[]>(BusTcpServer_OnDataReceived), tcpServer, modbus);
                return;
            }
            textBox1.AppendText("接收数据:" + HslCommunication.BasicFramework.SoftBasic.ByteToHexString(modbus) + Environment.NewLine);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }


            try
            {
                busTcpServer        = new HslCommunication.ModBus.ModbusTcpServer( );                                              // 实例化对象
                busTcpServer.LogNet = new HslCommunication.LogNet.LogNetSingle(Path.Combine(Application.StartupPath, "logs.txt")); // 配置日志信息
                busTcpServer.LogNet.BeforeSaveToFile += LogNet_BeforeSaveToFile;
                busTcpServer.OnDataReceived          += BusTcpServer_OnDataReceived;

                // add some accounts
                busTcpServer.AddAccount("admin", "123456");
                busTcpServer.AddAccount("hsl", "test");
                busTcpServer.UseSynchronousNet = checkBox2.Checked;

                ComboBox2_SelectedIndexChanged(null, new EventArgs( ));
                busTcpServer.IsStringReverse = checkBox3.Checked;
                busTcpServer.ServerStart(port);

                button1.Enabled  = false;
                panel2.Enabled   = true;
                button4.Enabled  = true;
                button11.Enabled = true;

                timerSecond?.Dispose( );
                timerSecond          = new System.Windows.Forms.Timer( );
                timerSecond.Interval = 1000;
                timerSecond.Tick    += TimerSecond_Tick;
                timerSecond.Start( );
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #6
0
 public FormTrustedClient(HslCommunication.ModBus.ModbusTcpServer modbusTcpServer)
 {
     InitializeComponent( );
     this.modbusTcpServer = modbusTcpServer;
 }