Advertisement
Guest User

Untitled

a guest
Aug 15th, 2013
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO.Ports;
  11. namespace Tutorial_select_0
  12. {
  13.     public partial class Config_Serial : Form
  14.     {
  15.         Form1 janela1;
  16.         string[] portas = {""};
  17.         bool reset2 = false;
  18.  
  19.  
  20.         public Config_Serial(Form1 x)
  21.         {
  22.             InitializeComponent();
  23.             janela1 = x;
  24.         }
  25.  
  26.         void busca_de_portas(bool x)
  27.         {
  28.             int num = portas.Length;
  29.             portas = SerialPort.GetPortNames();
  30.             if (num != portas.Length || x)
  31.             {
  32.                 comboBox1.Items.Clear();
  33.                 for (int i = 0; i < portas.Length; i++)
  34.                 {
  35.                     comboBox1.Items.Add(portas[i]);
  36.                 }
  37.             }
  38.         }
  39.  
  40.         private void Config_Serial_Load(object sender, EventArgs e)
  41.         {
  42.             busca_de_portas(true);
  43.         }
  44.  
  45.         private void timer1_Tick(object sender, EventArgs e)
  46.         {
  47.             busca_de_portas(false);
  48.         }
  49.  
  50.         private void Config_Serial_FormClosing(object sender, FormClosingEventArgs e)
  51.         {
  52.             try
  53.             {            
  54.                 janela1.Porta.BaudRate = Convert.ToInt32(comboBox2.Text);
  55.                 janela1.Porta.PortName = comboBox1.Text;
  56.                 janela1.Text = comboBox1.Text + "/" + comboBox2.Text;
  57.                 janela1.reset = reset2;          
  58.             }
  59.             catch
  60.             {
  61.                 DialogResult escolha;
  62.                 escolha = MessageBox.Show("Prencha todos os campos ", "Aviso", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
  63.                 if (escolha == System.Windows.Forms.DialogResult.OK)
  64.                 {
  65.                     e.Cancel = true;
  66.                 }
  67.             }
  68.         }
  69.  
  70.         private void checkBox1_CheckedChanged(object sender, EventArgs e)
  71.         {
  72.             if(checkBox1.Checked)
  73.             {
  74.                 reset2 = true;
  75.             }
  76.             else
  77.             {
  78.                 reset2 = false;
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement