Read_platform() public method

public Read_platform ( Plataforma, &plataforma ) : Respuesta,
plataforma Plataforma,
return Respuesta,
Example #1
0
    protected Chronopic.Plataforma chronopicInitialValue(Chronopic cp)
    {
        Chronopic.Plataforma myPlatformState = Chronopic.Plataforma.UNKNOW; //on (in platform), off (jumping), or unknow
        bool ok        = false;
        int  timeWait  = 50;                                                //wait 50ms between calls to Read_platform
        int  timeLimit = 1000;
        int  count     = 0;

        do
        {
            try {
                ok = cp.Read_platform(out myPlatformState);
            } catch {
                LogB.Warning("Manage called after finishing constructor, do later");
            }
            Thread.Sleep(timeWait);             //wait 50ms
            count += timeWait;
        } while (!ok && count < timeLimit);

        return(myPlatformState);
    }
Example #2
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;
        }
    }
Example #3
0
    /**********************/
    /* PROGRAMA PRINCIPAL */
    /**********************/
    public static void Main()
    {
        Chronopic.Plataforma estado_plataforma;
        Chronopic.Respuesta respuesta;
        Automata estado_automata;
        double timestamp;
        double toff;

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

        //-- Obtener el estado inicial de la plataforma
        respuesta=cp.Read_platform(out estado_plataforma);
        switch(respuesta) {
          case Chronopic.Respuesta.Error:
        Console.WriteLine("Error en comunicacion con Chronopic");
        return;
          case Chronopic.Respuesta.Timeout:
        Console.WriteLine("Chronopic no responde");
        return;
          default:
        break;
        }

        Console.WriteLine("Estado plataforma: {0}",estado_plataforma);

        //-- Establecer el estado inicial del automata
        if (estado_plataforma==Chronopic.Plataforma.ON)
          estado_automata=Automata.ON;
        else {
          Console.WriteLine("Suba a la plataforma para realizar el salto");

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

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

        Console.WriteLine("");
        Console.WriteLine("Puede saltar cuando quiera");
        Console.WriteLine("Pulse control-c para finalizar la sesion");
        Console.WriteLine("-----------------------------------------");

        while(true) {

          //-- Esperar a que llegue una trama
          do {
        respuesta = cp.Read_event(out timestamp, out estado_plataforma);
          } while (respuesta!=Chronopic.Respuesta.Ok);

          //-- 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("Tiempo: {0:f1} ms",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;
          }
          break;
          }

        }
    }
    /**********************/
    /* 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;
        }
    }
Example #5
0
    /**********************/
    /* PROGRAMA PRINCIPAL */
    /**********************/
    public static void Main()
    {
        Chronopic.Plataforma estado_plataforma;
        Chronopic.Respuesta  respuesta;
        Automata             estado_automata;
        double timestamp;
        double toff;

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

        //-- Obtener el estado inicial de la plataforma
        respuesta = cp.Read_platform(out estado_plataforma);
        switch (respuesta)
        {
        case Chronopic.Respuesta.Error:
            Console.WriteLine("Error en comunicacion con Chronopic");
            return;

        case Chronopic.Respuesta.Timeout:
            Console.WriteLine("Chronopic no responde");
            return;

        default:
            break;
        }

        Console.WriteLine("Estado plataforma: {0}", estado_plataforma);

        //-- Establecer el estado inicial del automata
        if (estado_plataforma == Chronopic.Plataforma.ON)
        {
            estado_automata = Automata.ON;
        }
        else
        {
            Console.WriteLine("Suba a la plataforma para realizar el salto");

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

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

        Console.WriteLine("");
        Console.WriteLine("Puede saltar cuando quiera");
        Console.WriteLine("Pulse control-c para finalizar la sesion");
        Console.WriteLine("-----------------------------------------");

        while (true)
        {
            //-- Esperar a que llegue una trama
            do
            {
                respuesta = cp.Read_event(out timestamp, out estado_plataforma);
            } while (respuesta != Chronopic.Respuesta.Ok);


            //-- 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("Tiempo: {0:f1} ms", 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;
                }
                break;
            }
        }
    }
Example #6
0
    // ----- change multitest firmware START ----->

    //change debounce time automatically on change menuitem mode (if multitest firmware)
    public bool ChangeMultitestFirmwarePre(int thresholdValue, int cpCount)
    {
        LogB.Information("ChangeMultitestFirmwareMaybe (A)");

        cpDoing = cpCount;

        //---- 1
        //bool ok = cp.Read_platform(out platformState);
        //seems better to have a new platformState:
        Chronopic.Plataforma ps;
        bool ok;

        if (cpDoing == 1)
        {
            ok = cp.Read_platform(out ps);
        }
        else
        {
            ok = cp2.Read_platform(out ps);
        }

        if (!ok)
        {
            LogB.Information("Chronopic has been disconnected");
            //createChronopicWindow(true, "");
            //chronopicWin.Connected = false;
            return(false);
        }

        /*
         * method 1. Unused
         * try {
         * ChronopicAuto ca = new ChronopicAutoCheck();
         * //problems with windows using this:
         * string chronopicVersion = ca.Read(chronopicWin.SP);
         * LogB.Debug("version: " + chronopicVersion);
         * } catch {
         * LogB.Information("Could not read from Chronopic with method 1");
         * return;
         * }*/

        //---- 2 try to communicate with multitest firmware (return if cannot connect)

        LogB.Information("ChangeMultitestFirmwareMaybe (B)");
        bool isChronopicAuto = false;

        try {
            string result = CheckAuto(out isChronopicAuto);
            LogB.Debug("version: " + result);
        } catch {
            LogB.Information("Could not read from Chronopic with method 2");
            return(false);
        }

        //---- 3 change debounce time
        LogB.Information("ChangeMultitestFirmwareMaybe (C)");
        if (isChronopicAuto)
        {
            bool changedOk = changeMultitestFirmwareDo(thresholdValue);
            if (!changedOk)
            {
                return(false);
            }
        }

        LogB.Information("ChangeMultitestFirmwareMaybe (D)");

        return(true);
    }
Example #7
0
    protected Chronopic.Plataforma chronopicInitialValue(Chronopic cp)
    {
        Chronopic.Plataforma myPlatformState  = Chronopic.Plataforma.UNKNOW; //on (in platform), off (jumping), or unknow
        bool ok = false;
        int timeWait = 50; //wait 50ms between calls to Read_platform
        int timeLimit = 1000;
        int count = 0;

        do {
            try {
                ok = cp.Read_platform(out myPlatformState);
            } catch {
                Log.WriteLine("Manage called after finishing constructor, do later");
            }
            Thread.Sleep(timeWait); //wait 50ms
            count += timeWait;
        } while (! ok && count < timeLimit);

        return myPlatformState;
    }