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