Пример #1
0
        static void Main(string[] args)
        {
            //55 AA 00 61 43 7A 00 00 43 B4 15 0D
            string deviceID            = "2";
            DeviceSingletonDriver dev3 = new DeviceSingletonDriver();

            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";
            DeviceSingletonDriver dev4 = new DeviceSingletonDriver();

            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           = "单例服务",
                NetReceiveBufferSize = 1024,
                DeliveryMode         = DeliveryMode.DeviceCode,
                ControlMode          = ControlMode.Singleton,
                MaxConnects          = 5000
            });

            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();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            DeviceSingletonDriver dev3 = new DeviceSingletonDriver();

            dev3.DeviceParameter.DeviceName     = "设备3";
            dev3.DeviceParameter.DeviceAddr     = 0;
            dev3.DeviceParameter.DeviceID       = 2;
            dev3.DeviceDynamic.DeviceID         = 2;
            dev3.DeviceParameter.NET.RemoteIP   = "127.0.0.1";
            dev3.DeviceParameter.NET.RemotePort = 9600;
            dev3.CommunicateType = CommunicateType.NET;
            dev3.Initialize(2);

            IServer server = new ServerFactory().CreateServer(new ServerConfig()
            {
                ServerName  = "服务1",
                ControlMode = ControlMode.Singleton
            });

            server.AddDeviceCompleted    += server_AddDeviceCompleted;
            server.DeleteDeviceCompleted += server_DeleteDeviceCompleted;
            server.SocketConnected       += server_SocketConnected;
            server.SocketClosed          += server_SocketClosed;
            server.Start();

            server.AddDevice(dev3);

            TestService.Service s = new TestService.Service();
            s.ServiceLog += s_AppServiceLog;
            server.AddService((IService)s);

            Graphics g = new Graphics();

            server.AddGraphicsShow((IGraphicsShow)g);

            while ("exit" == Console.ReadLine())
            {
                server.Stop();
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            //55 AA 00 61 43 7A 00 00 43 B4 15 0D
            DeviceSingletonDriver dev1 = new DeviceSingletonDriver();

            dev1.DeviceParameter.DeviceName     = "网络设备";
            dev1.DeviceParameter.DeviceAddr     = 0;
            dev1.DeviceParameter.DeviceID       = "0";
            dev1.DeviceDynamic.DeviceID         = "0";
            dev1.DeviceParameter.DeviceCode     = "0";
            dev1.DeviceParameter.NET.RemoteIP   = "127.0.0.1";
            dev1.DeviceParameter.NET.RemotePort = 9600;
            dev1.CommunicateType = CommunicateType.NET;
            dev1.Initialize("0");

            IServer server = new ServerManager().CreateServer(new ServerConfig()
            {
                ServerName           = "单例服务",
                NetReceiveBufferSize = 1024,
                ControlMode          = ControlMode.Singleton,
                MaxConnects          = 4000
            });

            server.AddDeviceCompleted    += server_AddDeviceCompleted;
            server.DeleteDeviceCompleted += server_DeleteDeviceCompleted;
            server.SocketConnected       += server_SocketConnected;
            server.SocketClosed          += server_SocketClosed;
            server.Start();

            server.AddDevice(dev1);

            while ("exit" == Console.ReadLine())
            {
                server.Stop();
            }
        }