예제 #1
0
        /// <summary>
        /// Realiza las acciones pertinentes para detener la simulación y luego reinicia las variables a sus
        /// valores originales.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Simulation_Stop_Click(object sender, EventArgs e)
        {
            try
            {
                #region User Interface
                pictureBox_Simulation_State.BackColor = Color.Red;

                ToolStripStatusLabel_Time_Write(toolStripStatusLabel_Time, "0");
                ToolStripStatusLabel_ChartPrintingTime_Write(toolStripStatusLabel_ChartPrintingTime, "0");
                ToolStripStatusLabel_Status_Write(toolStripStatusLabel_ProgramStatus, "Simulación detenida");
                #endregion

                #region Flags
                InvertFlagState(ref flag_Thread_DataReception_DLL_Enabled, ref flag_Thread_Printing_Enabled);
                button_EmulatorInterface_Connect.Enabled = true;
                InvertButtonsHabilitation(button_Simulation_Start, button_Simulation_Pause, button_Simulation_Stop);

                flag_Thread_DataReception_DLL_IsPaused = flag_Thread_Printing_IsPaused = false;
                #endregion

                #region Reset
                dllLinker.ResetValues();
                ChartPrinting.Erase(chart_DataOutput, ref data);
                #endregion

                #region Debug & Tracing
                Debug.WriteLine("Simulacion detenida.");
                #endregion
            }
            catch (Exception ex)
            {
                string windowTitle = "Error pausando la simulación";
                MessageBox.Show(ex.Message, windowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
 /// <summary>
 /// Cambia la señal de salida a mostar en la gráfica.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void comboBox_Simulation_OutSignal_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         ChartPrinting.Erase(chart_DataOutput, ref flag_Thread_Printing_IsPaused);
         simulator_SelectedSignal = comboBox_Simulation_OutSignal.SelectedItem.ToString();
         chart_DataOutput.Series.ElementAt <Series>(0).Name = simulator_SelectedSignal;
     }
     catch (Exception ex)
     {
         string windowTitle = "Simualador: Error cambiando la señal";
         MessageBox.Show(ex.Message + "\r\n Event: comboBox_Simulation_OutSignal_SelectedIndexChanged",
                         windowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #3
0
        /// <summary>
        /// Hilo encargado de la impresion y comportamiento de la gráfica.
        /// </summary>
        void Thread_ChartPrinting()
        {
            try
            {
                Debug.WriteLine("Iniciando hilo de impresion de la gráfica...");
                int chartPointsCount = 0;

                //Inician los contadores
                stopWatch_FilledChart.Start();

                for (; ;)
                {
                    if (flag_Thread_Printing_Enabled)
                    {
                        Thread.Sleep(refreshRate);
                        if (!flag_Thread_Printing_IsPaused)
                        {
                            //Se reinicia el contador de tiempo en caso de que se haya pausado
                            if (stopWatch_General.ElapsedTicks != 0)//Se verifica de esta manera para que sea lo más rapido posible
                            {
                                stopWatch_FilledChart.Start();
                            }

                            #region UART Printing
                            if (flag_Thread_DataReception_UART_Enabled)
                            {
                                ChartPrinting.PrintConcurrent(chart_DataOutput, data, samplingTime);
                            }
                            #endregion

                            #region Simulation Printing
                            if (flag_Thread_DataReception_DLL_Enabled)
                            {
                                //[NOTE] Esta es la forma más rapida comparada a imprimir hasta esperar
                                //por una cantidad finita de datos
                                ChartPrinting.PrintConcurrent(chart_DataOutput, data, samplingTime);
                            }
                            #endregion

                            #region User Interface
                            //Impresion del tiempo de impresion por pantalla
                            chartPointsCount = chart_DataOutput.Series.ElementAt <Series>(0).Points.Count;

                            if (chartPointsCount != 0 && stopWatch_FilledChart.IsRunning == false)
                            {
                                //Se han de perder algunos nanosegundos posiblemente, pero parece no ser significativo
                                stopWatch_FilledChart.Start();
                            }
                            else if (chartPointsCount == 0 && stopWatch_FilledChart.IsRunning == true)
                            {
                                ToolStripStatusLabel_ChartPrintingTime_Write(toolStripStatusLabel_ChartPrintingTime,
                                                                             stopWatch_FilledChart.ElapsedMilliseconds.ToString());
                                stopWatch_FilledChart.Reset();
                            }
                            #endregion
                        }
                        else//Si esta pausado
                        {
                            stopWatch_FilledChart.Stop();
                        }
                    }
                    else
                    {
                        //Se reinician los contadores
                        stopWatch_FilledChart.Reset();

                        ToolStripStatusLabel_ChartPrintingTime_Write(toolStripStatusLabel_ChartPrintingTime,
                                                                     stopWatch_FilledChart.ElapsedMilliseconds.ToString());

                        Debug.WriteLine("Hilo de impresion de la gráfica finalizado.");
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                string windowTitle = "Error en el hilo de impresión de la gráfica";
                MessageBox.Show(ex.Message, windowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }