private void button1_Click(object sender, EventArgs e) { if (!int.TryParse(textBox2.Text, out int port)) { MessageBox.Show(DemoUtils.PortInputWrong); return; } try { busTcpServer = new Communication.ModBus.ModbusTcpServer(); // 实例化对象 busTcpServer.LogNet = new Communication.LogNet.LogNetSingle("logs.txt"); // 配置日志信息 busTcpServer.LogNet.BeforeSaveToFile += LogNet_BeforeSaveToFile; busTcpServer.OnDataReceived += BusTcpServer_OnDataReceived; 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); } }
public FormTrustedClient(Communication.ModBus.ModbusTcpServer modbusTcpServer) { InitializeComponent( ); this.modbusTcpServer = modbusTcpServer; }