Exemple #1
0
        /// <summary>
        /// Realiza las operaciones necesarias para la utilizacion de la interfaz del emulador.
        /// </summary>
        public void Initialize_EmulatorInterface()
        {
            #region Buttons
            //Habilitacion
            button_EmulatorInterface_Connect.Enabled     = true;
            button_EmulatorInterface_Disconnect.Enabled  = false;
            button_EmulatorInterface_SendCommand.Enabled = false;
            #endregion Buttons

            #region ComboBoxes
            //DataSources
            comboBox_EmulatorInterface_Ports.DataSource       = SerialUART.GetPorts();
            comboBox_EmulatorInterface_BaudRates.DataSource   = SerialUART.GetBaudRates();
            comboBox_EmulatorInterface_Parity.DataSource      = SerialUART.GetParity();
            comboBox_EmulatorInterface_FlowControl.DataSource = SerialUART.GetFlowControl();
            comboBox_EmulatorInterface_StopBits.DataSource    = SerialUART.GetStopBits();
            comboBox_EmulatorInterface_DataBits.DataSource    = SerialUART.GetDataBits();

            //Indices por defecto
            comboBox_EmulatorInterface_BaudRates.SelectedIndex =
                comboBox_EmulatorInterface_BaudRates.FindStringExact("9600");
            comboBox_EmulatorInterface_Parity.SelectedIndex =
                comboBox_EmulatorInterface_Parity.FindStringExact("None");
            comboBox_EmulatorInterface_FlowControl.SelectedIndex =
                comboBox_EmulatorInterface_FlowControl.FindStringExact("None");
            comboBox_EmulatorInterface_StopBits.SelectedIndex =
                comboBox_EmulatorInterface_StopBits.FindStringExact("One");
            comboBox_EmulatorInterface_DataBits.SelectedIndex =
                comboBox_EmulatorInterface_DataBits.FindStringExact("8");

            //Comboboxes no editables
            SetComboBoxAsNoEditable(comboBox_EmulatorInterface_Ports,
                                    comboBox_EmulatorInterface_BaudRates,
                                    comboBox_EmulatorInterface_Parity,
                                    comboBox_EmulatorInterface_FlowControl,
                                    comboBox_EmulatorInterface_StopBits,
                                    comboBox_EmulatorInterface_DataBits);
            #endregion ComboBoxes

            #region Textboxes
            textBox_EmulatorInterface_ReceivedData.Multiline = true;
            #endregion
        }
Exemple #2
0
        /// <summary>
        /// Realiza las acciones pertinentes para iniciar la conexión UART y recibir datos para mostrar en pantalla.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_EmulatorInterface_Connect_Click(object sender, EventArgs e)
        {
            try
            {
                pictureBox_EmulatorInterface_ConnectionState.BackColor = Color.Lime;

                uart = new SerialUART(comboBox_EmulatorInterface_Ports.SelectedItem.ToString(),
                                      Convert.ToInt32(comboBox_EmulatorInterface_BaudRates.SelectedItem.ToString()),
                                      SerialUART.InterpretFlowControl(comboBox_EmulatorInterface_FlowControl.SelectedItem.ToString()),
                                      SerialUART.InterpretParity(comboBox_EmulatorInterface_Parity.SelectedItem.ToString()),
                                      (int)comboBox_EmulatorInterface_DataBits.SelectedItem,
                                      SerialUART.InterpretStopBits(comboBox_EmulatorInterface_StopBits.SelectedItem.ToString()),
                                      true);
#if !ONLYUI
                thread_DataReception_UART = new Thread(new ThreadStart(Thread_DataReception_UART));
                thread_DataReception_UART.IsBackground = true;
                thread_DataReception_UART.Priority     = ThreadPriority.Highest;

                thread_ChartPrinting = new Thread(new ThreadStart(Thread_ChartPrinting));
                thread_ChartPrinting.IsBackground = true;
                thread_ChartPrinting.Priority     = ThreadPriority.Normal;

                thread_TextPrinting = new Thread(new ThreadStart(Thread_TextPrinting));
                thread_TextPrinting.IsBackground = true;
                thread_TextPrinting.Priority     = ThreadPriority.Lowest;

                thread_DataReception_UART.Start();
                thread_ChartPrinting.Start();
                thread_TextPrinting.Start();
#endif

                InvertFlagState(ref flag_Thread_DataReception_UART_Enabled, ref flag_Thread_Printing_Enabled);

                InvertButtonsHabilitation(button_EmulatorInterface_Connect,
                                          button_EmulatorInterface_Disconnect,
                                          button_EmulatorInterface_SendCommand,
                                          button_Simulation_Start);

                InvertComboBoxHabilitation(comboBox_EmulatorInterface_BaudRates,
                                           comboBox_EmulatorInterface_FlowControl,
                                           comboBox_EmulatorInterface_Parity,
                                           comboBox_EmulatorInterface_Ports,
                                           comboBox_EmulatorInterface_StopBits,
                                           comboBox_EmulatorInterface_DataBits);

                ToolStripStatusLabel_Status_Write(toolStripStatusLabel_ProgramStatus, "Interface conectada...");
                Debug.WriteLine("Conexion UART iniciada.");
            }
            catch (Exception ex)
            {
                string windowTitle = "Error de conexíon UART";
                MessageBox.Show(ex.Message, windowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
#if !ONLYUI
                if (uart != null)
                {
                    uart.Dispose();
                }
#endif
            }
        }