Home > Article > Backend Development > Network communication controller grouping to improve interactive load balancing capabilities example tutorial
ServerSuperIO originally had only one network controller in the network communication mode. In the automatic control mode, concurrent mode and singleton mode, the returned data is processed asynchronously, and there will be no performance. question. However, in polling mode, a network controller must operate the sending and receiving of the device driver one by one in sequence, so the polling cycle may be too long and the frequency of reading data cannot be reached.
In order to solve the above problems, the network controller grouping function is now added to the device driver parameters. The network controller will control the device driver according to the group name set by the device parameters. For example, in polling mode, there are 1,000 device drivers, and the same group name can be set for every 10 device drivers. These 10 device drivers are controlled by the same network controller. If data is read every 1 second, then each The polling cycle of the device driver is 10 seconds, which is similar to other network controllers.
According to the ControllerGroup that sets the device driver network parameters, the device driver can be assigned to run in different network controls, and is applicable For polling, automatic control, concurrency and singleton control modes.
By the way, the serial port controller can be assigned to different serial port controllers by setting the serial port number of the device driver. This controller can only be used in polling control mode.
static void Main(string[] args) { string deviceID = "2"; DeviceDriver dev3 = new DeviceDriver(); dev3.DeviceParameter.DeviceName = "设备2"; dev3.DeviceParameter.DeviceAddr = 0; dev3.DeviceParameter.DeviceID = deviceID; dev3.DeviceParameter.DeviceCode = deviceID; dev3.DeviceDynamic.DeviceID = deviceID; dev3.DeviceParameter.NET.RemoteIP = "127.0.0.1"; dev3.DeviceParameter.NET.RemotePort = 9600; dev3.DeviceParameter.NET.ControllerGroup = "G2"; dev3.CommunicateType = CommunicateType.NET; dev3.DeviceParameter.NET.WorkMode = WorkMode.TcpServer; dev3.Initialize(deviceID); deviceID = "3"; DeviceDriver dev4 = new DeviceDriver(); dev4.DeviceParameter.DeviceName = "设备3"; dev4.DeviceParameter.DeviceAddr = 0; dev4.DeviceParameter.DeviceID = deviceID; dev4.DeviceParameter.DeviceCode = deviceID; dev4.DeviceDynamic.DeviceID = deviceID; dev4.DeviceParameter.NET.RemoteIP = "127.0.0.1"; dev4.DeviceParameter.NET.RemotePort = 9600; dev4.DeviceParameter.NET.ControllerGroup = "G3"; dev4.CommunicateType = CommunicateType.NET; dev4.Initialize(deviceID); IServer server = new ServerManager().CreateServer(new ServerConfig() { ServerName = "服务1", ComReadTimeout = 1000, ComWriteTimeout = 1000, NetReceiveTimeout = 1000, NetSendTimeout = 1000, ControlMode = ControlMode.Loop, SocketMode = SocketMode.Tcp, StartReceiveDataFliter = false, ClearSocketSession = true, StartCheckPackageLength = false, CheckSameSocketSession = false, }); server.AddDeviceCompleted += server_AddDeviceCompleted; server.DeleteDeviceCompleted += server_DeleteDeviceCompleted; server.SocketConnected+=server_SocketConnected; server.SocketClosed+=server_SocketClosed; server.Start(); server.AddDevice(dev3); server.AddDevice(dev4); while ("exit"==Console.ReadLine()) { server.Stop(); } }
The above is the detailed content of Network communication controller grouping to improve interactive load balancing capabilities example tutorial. For more information, please follow other related articles on the PHP Chinese website!