예제 #1
0
        static void Main(string[] args)
        {
            Console.Title          = "Monitoring";
            Console.OutputEncoding = Encoding.UTF8;
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);

            string port  = "COM5";
            int    speed = 96000;

            if (args.Length >= 2)
            {
                port = args[0];
                try
                {
                    speed = Convert.ToInt32(args[1]);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Invalid speed!");
                    Environment.Exit(1);
                }
            }

            monitoring = new COM.COM(port, speed);

            try
            {
                monitoring.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(1);
            }
            monitoring.DataReceived += new SerialDataReceivedEventHandler(ByteReceivedFromServer);

            while (true)
            {
                monitoring.SendByte(11);
                Thread.Sleep(1000);
            }

            Thread.Sleep(Timeout.Infinite);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.Title          = "Client";
            Console.OutputEncoding = Encoding.UTF8;
            Console.InputEncoding  = Encoding.UTF8;
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);

            string port  = "COM3";
            int    speed = 96000;

            if (args.Length >= 2)
            {
                port = args[0];
                try
                {
                    speed = Convert.ToInt32(args[1]);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Invalid speed!");
                    Environment.Exit(1);
                }
            }

            client = new COM.COM(port, speed);
            try
            {
                client.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(1);
            }

            while (true)
            {
                ConsoleKeyInfo key = Console.ReadKey();
                byte           b   = Encoding.Default.GetBytes(key.KeyChar.ToString()).First();
                client.SendByte(b);
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.Title = "Multi";

            string portClient  = "COM3";
            int    speedClient = 9600;
            string portServer  = "COM4";
            int    speedServer = 9600;

            client = Window.OpenBox("Input", 20, 12, new BoxStyle()
            {
                ThickNess = LineThickNess.Single,
                Title     = new Colors(White, Blue)
            });

            server = Window.OpenBox("Output", 20, 12, new BoxStyle()
            {
                ThickNess = LineThickNess.Single,
                Title     = new Colors(White, Blue)
            });

            monitoring = Window.OpenBox("Status", 20, 0, 80, 24, new BoxStyle()
            {
                ThickNess = LineThickNess.Single,
                Title     = new Colors(White, Blue)
            });

            if (args.Length >= 4)
            {
                bool isClient = true;
                portClient = args[0];
                portServer = args[2];
                try
                {
                    speedClient = Convert.ToInt32(args[1]);
                    isClient    = false;
                    speedServer = Convert.ToInt32(args[3]);
                }
                catch (Exception e)
                {
                    if (isClient)
                    {
                        Write(client, "Invalid speed!");
                    }
                    else
                    {
                        Write(server, "Invalid speed!");
                    }
                    Console.ReadKey(true);
                    Environment.Exit(1);
                }
            }

            clientCOM = new COM.COM(portClient, speedClient);

            try
            {
                clientCOM.Open();
            }
            catch (Exception e)
            {
                Write(client, e.Message);
                Console.ReadKey(true);
                Environment.Exit(1);
            }

            initClientLine = string.Format("Init {0} : {1} baud rate; stop bits {2}; RTS is enable {3}; Parity {4}.", portClient, speedClient, clientCOM.StopBits, clientCOM.RtsEnable, clientCOM.Parity);
            logs.Add(initClientLine);
            endMonitoringPos++;
            WriteLine(monitoring, initClientLine);

            serverCOM = new COM.COM(portServer, speedServer);

            try
            {
                serverCOM.Open();
            }
            catch (Exception e)
            {
                Write(server, e.Message);
                Console.ReadKey(true);
                Environment.Exit(1);
            }

            initServerLine = string.Format("Init {0} - {1} baud rate; stop bits {2}; RTS is enable {3}; Parity {4}.", portServer, speedServer, serverCOM.StopBits, serverCOM.RtsEnable, serverCOM.Parity);
            logs.Add(initServerLine);
            endMonitoringPos++;
            WriteLine(monitoring, initServerLine);

            serverCOM.DataReceived += new SerialDataReceivedEventHandler(ByteReceivedFromClient);

            while (true)
            {
                ConsoleKeyInfo key = Console.ReadKey(true);

                if (key.Key == ConsoleKey.UpArrow)
                {
                    if (endMonitoringPos < logs.Count)
                    {
                        endMonitoringPos++;
                    }

                    Logging(endMonitoringPos);
                    continue;
                }
                else if (key.Key == ConsoleKey.DownArrow)
                {
                    if (endMonitoringPos - 21 > 0)
                    {
                        endMonitoringPos--;
                    }

                    Logging(endMonitoringPos);
                    continue;
                }

                if (key.Key == ConsoleKey.Enter)
                {
                    WriteLine(client, "");
                }
                else
                {
                    Write(client, key.KeyChar.ToString());
                }
                byte   b   = Encoding.Default.GetBytes(key.KeyChar.ToString()).First();
                string log = string.Format("Byte sended: '{0}'.\n", (char)b);
                logs.Add(log);
                WriteLine(monitoring, log);
                endMonitoringPos++;
                clientCOM.SendByte(b);
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            Console.Title          = "Server";
            Console.OutputEncoding = Encoding.UTF8;
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);

            string port  = "COM4";
            int    speed = 96000;

            if (args.Length >= 2)
            {
                port = args[0];
                try
                {
                    speed = Convert.ToInt32(args[1]);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Invalid speed!");
                    Environment.Exit(1);
                }
            }

            string portMonitoring  = null;
            int    speedMonitoring = 0;

            if (args.Length >= 4)
            {
                portMonitoring = args[2];
                try
                {
                    speedMonitoring = Convert.ToInt32(args[3]);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Invalid speed!");
                    Environment.Exit(1);
                }
            }

            server = new COM.COM(port, speed);

            logs.Enqueue(string.Format("[{2}] {0} - {1}\n", port, speed, DateTime.Now.ToString("dd.MM/yyyy HH:mm:ss")));

            try
            {
                server.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(1);
            }

            server.DataReceived += new SerialDataReceivedEventHandler(ByteReceivedFromClient);

            if (portMonitoring != null)
            {
                monitoring = new COM.COM(portMonitoring, speedMonitoring);
                try
                {
                    monitoring.Open();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Environment.Exit(1);
                }
                monitoring.DataReceived += new SerialDataReceivedEventHandler(ByteReceivedFromMonitoring);
            }

            Thread.Sleep(Timeout.Infinite);
        }