Ejemplo n.º 1
0
    static void Main(string[] args)
    {
        bool error = false;
        if (args.Length != 2) {
            Console.WriteLine("Syntax: program.exe <port> <baudrate>");
            Console.WriteLine("port        - can be in form of /dev/ttyS0 or com2 or /udp/ipaddress/port");
            Console.WriteLine("baudrate    - any baudrate like 19200 (for udp baudrate could be any number)");
            Console.WriteLine("");
            Console.WriteLine("example: program.exe /dev/ttyUSB0 19200");
            Console.WriteLine("example: program.exe /udp/192.168.0.10/1100 0");
            error = true;
            return;
        }

        if (!error) {
            //Console.WriteLine("arg0: " + args[0] + "\n");
            argPort = args[0];
            argBaud = Int32.Parse(args[1]);
        }

        if (!error) {
            if (DEBUG_LEVEL>0) {
                Console.WriteLine("canDaemon");
                Console.WriteLine("Commands:");
                //Console.WriteLine("reset - reset communication.");
                Console.WriteLine("exit  - exit program");
                Console.WriteLine("");
                Thread.Sleep(1000);
            }

            sc = new SerialConnection();
            try {
                sc.setConfiguration(argBaud, System.IO.Ports.Parity.None, argPort, System.IO.Ports.StopBits.One, 8, false);
            }
            catch (Exception e) { Console.WriteLine("Error: " + e.Message); }
            if (!sc.open()) {
                Console.WriteLine("Error opening port to target");
                //... här ska man testa om igen...

            } else {

                d = new Daemon(sc);
                tcps = new TcpServer(1200);
                d.addServer(tcps);

                Thread t = new Thread(d.thread);
                t.Start();

                string instr;
                do {
                    //Console.Write("> ");
                    instr = Console.ReadLine().ToLower();
                } while (parseInput(instr));
                d.stop();
            }
        }
    }