Пример #1
0
        static void Main(string[] args)
        {
            var settings = ConfigurationManager.AppSettings;
            var port = settings["COM_PORT"];
            var speed = Convert.ToInt32(settings["COM_SPEED"]);
            var tcpPort = Convert.ToInt32(settings["TCP_PORT"]);
            serial = new SerialManager(port, speed);
            Console.WriteLine("UART: " + port + " - " + speed);
            server = new HardwareTcpServer(tcpPort);
            server.OnServerState += server_OnServerState;
            server.OnClientState += server_OnClientState;
            server.OnData += server_OnData;
            serial.OnReceive += serial_OnReceive;
            serial.OnStateChange += serial_OnStateChange;
            serial.Connect();

           // bridge = new HttpToUartBridge(6200);

            TcpListener listener = new TcpListener(IPAddress.Parse("188.127.233.35"), tcpPort);
            listener.Start();
            Console.WriteLine("TCP: " + tcpPort);
            while (Thread.CurrentThread.ThreadState == ThreadState.Running)
            {
                Console.WriteLine("Listening " + tcpPort);
                while (!listener.Pending())
                {
                    Thread.Sleep(300);
                }
                server.AcceptTcpClient(listener.AcceptSocket());
            }
            Console.WriteLine("Stopped");
            listener.Stop();
            server.Close();
            serial.Close();
        }
Пример #2
0
 static void Main()
 {
     var settings = ConfigurationManager.AppSettings;
     var port = settings["COM_PORT"];
     var speed = Convert.ToInt32(settings["COM_SPEED"]);
     var tcpPort = Convert.ToInt32(settings["TCP_PORT"]);
     var httpPort = Convert.ToInt32(settings["HTTP_PORT"]);
     var cncAddr = Convert.ToByte(settings["CNC_ADDR"]);
     SerialPort = new SerialAddressedManager(port, speed);
     SerialPort.DeviceAddr = cncAddr;
     //SerialPort.Connect();
     HttpServer = new SmallHttpServer(httpPort);
     HttpServer.Start();
     TcpServer = new HardwareTcpServer(tcpPort);
     TcpServer.Start();
     CncController.Init(SerialPort, Application.StartupPath, cncAddr);
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new fmMain());
     HttpServer.Close();
     TcpServer.Close();
     SerialPort.Close();
     CncController.Close();
 }