//chronopic init should not touch gtk, for the threads public bool Do(int currentCp, out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS, string myPort, out string returnString, out bool success) { LogB.Information("starting connection with chronopic"); CancelledByUser = false; success = true; LogB.Information("chronopicInit-1"); LogB.Information(string.Format("chronopic port: {0}", myPort)); mySp = new SerialPort(myPort); try { mySp.Open(); LogB.Information("chronopicInit-2"); //-- Create chronopic object, for accessing chronopic myCp = new Chronopic(mySp); LogB.Information("chronopicInit-2.1"); myCp.Flush(); //if myCp has been cancelled if (myCp.AbortFlush) { LogB.Information("chronopicInit-2.2 cancelled"); success = false; myCp = new Chronopic(); //fake constructor } else { LogB.Information("chronopicInit-3"); //on windows, this check make a crash //i think the problem is: as we don't really know the Timeout on Windows (.NET) and this variable is not defined on chronopic.cs //the Read_platform comes too much soon (when cp is not totally created), and this makes crash //-- Obtener el estado inicial de la plataforma bool ok = false; LogB.Information("chronopicInit-4"); do { LogB.Information("chronopicInit-5"); ok = myCp.Read_platform(out myPS); LogB.Information("chronopicInit-6"); } while(!ok && !CancelledByUser); LogB.Information("chronopicInit-7"); if (!ok) { //-- Si hay error terminar LogB.Error(string.Format("Error: {0}", myCp.Error)); success = false; } } } catch { LogB.Error("chronopicInit-2.a catched"); success = false; myCp = new Chronopic(); //fake constructor } returnString = ""; return(success); }
/**********************/ /* 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; } }
//chronopic init should not touch gtk, for the threads public bool Do(int currentCp, out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS, string myPort, out string returnString, out bool success) { LogB.Information("starting connection with chronopic"); CancelledByUser = false; success = true; LogB.Information("chronopicInit-1"); LogB.Information(string.Format("chronopic port: {0}", myPort)); mySp = new SerialPort(myPort); try { mySp.Open(); LogB.Information("chronopicInit-2"); //-- Create chronopic object, for accessing chronopic myCp = new Chronopic(mySp); LogB.Information("chronopicInit-2.1"); myCp.Flush(); //if myCp has been cancelled if(myCp.AbortFlush) { LogB.Information("chronopicInit-2.2 cancelled"); success = false; myCp = new Chronopic(); //fake constructor } else { LogB.Information("chronopicInit-3"); //on windows, this check make a crash //i think the problem is: as we don't really know the Timeout on Windows (.NET) and this variable is not defined on chronopic.cs //the Read_platform comes too much soon (when cp is not totally created), and this makes crash //-- Obtener el estado inicial de la plataforma bool ok=false; LogB.Information("chronopicInit-4"); do { LogB.Information("chronopicInit-5"); ok = myCp.Read_platform(out myPS); LogB.Information("chronopicInit-6"); } while(! ok && ! CancelledByUser); LogB.Information("chronopicInit-7"); if (!ok) { //-- Si hay error terminar LogB.Error(string.Format("Error: {0}", myCp.Error)); success = false; } } } catch { LogB.Error("chronopicInit-2.a catched"); success = false; myCp = new Chronopic(); //fake constructor } bool connected = false; returnString = ""; if(success) { if(currentCp == 1) connected = true; returnString = string.Format(Catalog.GetString("<b>Connected</b> to Chronopic on port: {0}"), myPort); } else { returnString = Catalog.GetString("Problems communicating to chronopic."); if(currentCp == 1) { returnString += " " + Catalog.GetString("Changed platform to 'Simulated'"); returnString += Catalog.GetString("\n\nWe recommend to remove and connect USB cable."); } //this will raise on_radiobutton_simulated_ativate and //will put cpRunning to false, and simulated to true and cp.Close() if(currentCp == 1) { connected = false; } } return connected; }
/**********************/ /* 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; } }
//chronopic init should not touch gtk, for the threads public bool Do(int currentCp, out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS, string myPort, out string returnString, out bool success) { LogB.Information("starting connection with chronopic"); CancelledByUser = false; success = true; LogB.Information("chronopicInit-1"); LogB.Information(string.Format("chronopic port: {0}", myPort)); mySp = new SerialPort(myPort); try { mySp.Open(); LogB.Information("chronopicInit-2"); //-- Create chronopic object, for accessing chronopic myCp = new Chronopic(mySp); LogB.Information("chronopicInit-2.1"); myCp.Flush(); //if myCp has been cancelled if (myCp.AbortFlush) { LogB.Information("chronopicInit-2.2 cancelled"); success = false; myCp = new Chronopic(); //fake constructor } else { LogB.Information("chronopicInit-3"); //on windows, this check make a crash //i think the problem is: as we don't really know the Timeout on Windows (.NET) and this variable is not defined on chronopic.cs //the Read_platform comes too much soon (when cp is not totally created), and this makes crash //-- Obtener el estado inicial de la plataforma bool ok = false; LogB.Information("chronopicInit-4"); do { LogB.Information("chronopicInit-5"); ok = myCp.Read_platform(out myPS); LogB.Information("chronopicInit-6"); } while(!ok && !CancelledByUser); LogB.Information("chronopicInit-7"); if (!ok) { //-- Si hay error terminar LogB.Error(string.Format("Error: {0}", myCp.Error)); success = false; } } } catch { LogB.Error("chronopicInit-2.a catched"); success = false; myCp = new Chronopic(); //fake constructor } bool connected = false; returnString = ""; if (success) { if (currentCp == 1) { connected = true; } returnString = string.Format(Catalog.GetString("<b>Connected</b> to Chronopic on port: {0}"), myPort); } else { returnString = Catalog.GetString("Problems communicating to chronopic."); if (currentCp == 1) { returnString += " " + Catalog.GetString("Changed platform to 'Simulated'"); returnString += Catalog.GetString("\n\nWe recommend to remove and connect USB cable."); } //this will raise on_radiobutton_simulated_ativate and //will put cpRunning to false, and simulated to true and cp.Close() if (currentCp == 1) { connected = false; } } return(connected); }