예제 #1
0
    /**********************/
    /* PROGRAMA PRINCIPAL */
    /**********************/
    public static void Main(string[] args)
    {
        Chronopic.Plataforma estado_plataforma;
        Automata             estado_automata;
        double     timestamp;
        double     toff;
        double     ton;
        bool       ok;
        string     portName = "";
        string     fileName = "";
        TextWriter writer;

        //always output to a file, but if not specified, output here and rewrite it every chronojump_mini execution
        string defaultFileName = Path.Combine(getOutputDir(), "output");


        System.Threading.Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo("es-ES");
        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("es-ES");

        //connect with catalog.cs for using gettext translation
        Catalog.Init("chronojump", "./locale");

        //parameters passing only on linux
        if (!UtilAll.IsWindows())
        {
            if (args.Length > 2)
            {
                printSyntaxAndQuit();
            }

            for (int i = 0; i != args.Length; ++i)
            {
                Console.WriteLine("param[{0}]: {1}", i, args[i]);
                if (args[i].StartsWith("PORT="))
                {
                    portName = args[i].Substring(5);
                }
                else if (args[i].StartsWith("FILE="))
                {
                    fileName = args[i].Substring(5);
                    fileName = getOutputDir() + Path.DirectorySeparatorChar + fileName;
                }
                else
                {
                    printSyntaxAndQuit();
                }
            }
        }

        //detection of ports
        string messageInfo;

        //string messageDetected ="";

        if (UtilAll.IsWindows())
        {
            messageInfo = Constants.PortNamesWindows;

            /*
             * messageDetected = Catalog.GetString("Detected ports:") + "\n";
             *
             * string jumpLine = "";
             * foreach (string s in SerialPort.GetPortNames()) {
             *      messageDetected += jumpLine + s;
             *      jumpLine = "\n";
             * }
             */
        }
        else
        {
            messageInfo = Constants.PortNamesLinux;
        }

        messageInfo += string.Format("\n" + Catalog.GetString("More information on Chronojump manual"));

        Console.WriteLine("---------------------------");
        Console.WriteLine(messageInfo);
        Console.WriteLine("---------------------------");

        if (portName == "")
        {
            if (!UtilAll.IsWindows())
            {
                Console.WriteLine(UtilAll.DetectPortsLinux(false));                 //formatting
            }
            Console.WriteLine(Catalog.GetString("Print the port name where chronopic is connected:"));
            portName = Console.ReadLine();
        }

        //output file stuff
        fileName = manageFileName(fileName);
        if (fileName == "")
        {
            fileName = defaultFileName + "-" + portName.Replace("/", "") + ".csv";
        }

        writer = File.CreateText(fileName);


        Console.WriteLine(Catalog.GetString("Opening port...") + " " +
                          Catalog.GetString("Please touch the platform or click Chronopic TEST button"));
        //-- Crear puerto serie
        SerialPort sp;

        sp = new SerialPort(portName);

        //-- Abrir puerto serie. Si ocurre algun error
        //-- Se lanzara una excepcion
        try {
            sp.Open();
        } catch (Exception e) {
            Console.WriteLine(Catalog.GetString("Error opening serial port"));
            Console.WriteLine(e);
            Environment.Exit(1);
        }



        //-- Crear objeto chronopic, para acceder al chronopic
        Chronopic cp = new Chronopic(sp);

        cp.Flush();


        //-- Obtener el estado inicial de la plataforma
        // this do...while is here because currently there's no timeout on chronopic.cs on windows
        do
        {
            ok = cp.Read_platform(out estado_plataforma);
        } while(!ok);
        if (!ok)
        {
            //-- Si hay error terminar
            Console.WriteLine(string.Format(Catalog.GetString("Error: {0}"), cp.Error));
            System.Environment.Exit(-1);
        }
        Console.WriteLine(string.Format(Catalog.GetString("Platform state: {0}"), estado_plataforma));


        //Console.WriteLine("Automatic variables: ");
        //cp.Read_variables_automatic();


        //-- Establecer el estado inicial del automata
        if (estado_plataforma == Chronopic.Plataforma.ON)
        {
            estado_automata = Automata.ON;
        }
        else
        {
            Console.WriteLine(Catalog.GetString("Go up platform for jumping"));

            //-- Esperar a que llegue una trama con el estado de la plataforma
            //-- igual a ON. Esto indica que el usuario se ha subido
            do
            {
                ok = cp.Read_event(out timestamp, out estado_plataforma);
            } while (!ok);

            //-- Se han subido a la plataforma
            estado_automata = Automata.ON;
        }

        Console.WriteLine("");
        Console.WriteLine(Catalog.GetString("Jump when prepared"));
        Console.WriteLine(Catalog.GetString("Press CTRL-c for ending session"));
        Console.WriteLine("-----------------------------------------");

        double count = 1.0;

        Console.WriteLine("  TC(ms) TF(ms)");
        writer.WriteLine("count;TC(ms);TF(ms)");

        while (true)
        {
            //-- Esperar a que llegue una trama
            do
            {
                ok = cp.Read_event(out timestamp, out estado_plataforma);
            } while (ok == false);


            //-- Segun el estado del automata
            switch (estado_automata)
            {
            case Automata.OFF:                     //-- Usuario estaba en el aire

                //-- Si ha aterrizado
                if (estado_plataforma == Chronopic.Plataforma.ON)
                {
                    //-- Pasar al estado ON
                    estado_automata = Automata.ON;

                    //-- Registrar tiempo de vuelo
                    toff = timestamp;

                    //-- Imprimir informacion
                    Console.WriteLine("{0:f1}", toff);
                    writer.WriteLine("{0:f1}", toff);
                }
                break;

            case Automata.ON:                     //-- Usuario estaba en la plataforma

                //-- Si ahora esta en el aire...
                if (estado_plataforma == Chronopic.Plataforma.OFF)
                {
                    //-- Pasar al estado OFF
                    estado_automata = Automata.OFF;

                    //-- Registrar tiempo de contacto
                    ton = timestamp;

                    //-- Imprimir informacion
                    Console.Write(count + " {0:f1} ", ton);
                    writer.Write(count + ";{0:f1};", ton);
                }
                break;
            }

            writer.Flush();

            count += .5;
        }
    }
예제 #2
0
    public HelpPorts()
    {
        Glade.XML gladeXML;
        gladeXML = Glade.XML.FromAssembly(Util.GetGladePath() + "chronojump.glade", "dialog_help_ports", "chronojump");
        gladeXML.Autoconnect(this);

        //put an icon to window
        UtilGtk.IconWindow(dialog_help_ports);

        string messageInfo;
        string messageDetected = "";


        if (UtilAll.IsWindows())
        {
            messageInfo = Constants.PortNamesWindows;

            /*
             * autodetection disabled on Linux and windows because mono doesn't allow it
             * string jumpLine = "";
             * foreach (string s in SerialPort.GetPortNames()) {
             *      messageDetected += jumpLine + s;
             *      jumpLine = "\n";
             * }
             */

            messageDetected = string.Format(Catalog.GetString("Auto-Detection currently disabled"));
        }
        else
        {
            messageInfo     = Constants.PortNamesLinux;
            messageDetected = UtilAll.DetectPortsLinux(true);             //formatting
            button_check_port.Hide();
            button_force_port.Hide();
        }

        label_info.Text          = messageInfo;
        label_info.UseMarkup     = true;
        label_detected.Text      = messageDetected;
        label_detected.UseMarkup = true;

        if (UtilAll.IsWindows())
        {
            label_help_info.Text =
                Constants.FindDriverWindows + "\n\n" +
                Catalog.GetString("Ports above COM4 may not work.") + "\n" +
                Catalog.GetString("If you want a safer port, press:") + "\n" +
                Catalog.GetString("Force Chronopic to port <b>COM1 - COM4</b>'.");
        }
        else
        {
            label_help_info.Text = Constants.FindDriverOthers;
        }

        label_help_info.UseMarkup = true;

        label_help_manual.Text =
            Catalog.GetString("More information on <b>Chronojump Manual</b>") + "\n" +
            "<i>" + Path.GetFullPath(Util.GetManualDir()) + "</i>\n\n" +
            Catalog.GetString("Newer versions will be on this site:") + "\n" +
            "<i>http://chronojump.org/documents.html</i>";
        label_help_manual.UseMarkup = true;
    }