Ejemplo n.º 1
0
        private void ButtonScanPort_Click(object sender, EventArgs e)
        {
            PanelConnection.Focus();
            if (LabelStatus.Text == "Status : Connected")
            {
                MessageBox.Show("Conncetion in progress, please Disconnect to scan the new port.", MessageBoxButtons.OK.ToString());
                return;
            }

            ComboBoxPort.Items.Clear();
            Array myPort;
            int   i;

            myPort = System.IO.Ports.SerialPort.GetPortNames();
            ComboBoxPort.Items.AddRange((object[])myPort);
            i = ComboBoxPort.Items.Count;
            i = i - i;
            try
            {
                ComboBoxPort.SelectedIndex = i;
                ButtonConnect.Enabled      = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Com port not detected", ex.Message);
                ComboBoxPort.Text = "";
                ComboBoxPort.Items.Clear();
                return;
            }

            ComboBoxPort.DroppedDown = true;
        }
Ejemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.CenterToScreen();
            PanelConnection.Focus();
            CircularProgressBarHumidity.Value = 0;
            ComboBoxBaudRate.SelectedIndex    = 0;
            for (int i = 0; i <= 30; i += 1)
            {
                Chart1.Series["Humidity       "].Points.AddY(0);
                if (Chart1.Series[0].Points.Count == ChartLimit)
                {
                    Chart1.Series[0].Points.RemoveAt(0);
                }

                Chart2.Series["Temperature"].Points.AddY(0);
                if (Chart2.Series[0].Points.Count == ChartLimit)
                {
                    Chart2.Series[0].Points.RemoveAt(0);
                }
            }

            Chart1.ChartAreas[0].AxisY.Maximum = 180;
            Chart1.ChartAreas[0].AxisY.Minimum = -20;
            Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = false;
            Chart2.ChartAreas[0].AxisY.Maximum = 70;
            Chart2.ChartAreas[0].AxisY.Minimum = -30;
            Chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = false;
            PictureBoxPBTemp.Height = 0;
        }
Ejemplo n.º 3
0
 private void ButtonDisconnect_Click(object sender, EventArgs e)
 {
     PanelConnection.Focus();
     TimerSerial.Stop();
     SerialPort1.Close();
     ButtonDisconnect.SendToBack();
     ButtonConnect.BringToFront();
     LabelStatus.Text = "Status : Disconnect";
     PictureBoxStatusConnection.Visible   = true;
     PictureBoxStatusConnection.BackColor = Color.Red;
 }
Ejemplo n.º 4
0
 private void ButtonConnect_Click(object sender, EventArgs e)
 {
     PanelConnection.Focus();
     try
     {
         SerialPort1.BaudRate = Convert.ToInt32(ComboBoxBaudRate.SelectedItem);
         SerialPort1.PortName = ComboBoxPort.SelectedItem.ToString();
         SerialPort1.Open();
         TimerSerial.Start();
         LabelStatus.Text = "Status : Connected";
         ButtonConnect.SendToBack();
         ButtonDisconnect.BringToFront();
         PictureBoxStatusConnection.BackColor = Color.Green;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Please check the Hardware, COM, Baud Rate and try again.", ex.Message);
     }
 }
Ejemplo n.º 5
0
 private void ComboBoxPort_DropDown_1(object sender, EventArgs e)
 {
     PanelConnection.Focus();
 }
Ejemplo n.º 6
0
 private void ComboBoxBaudRate_SelectedIndexChanged(object sender, EventArgs e)
 {
     PanelConnection.Focus();
 }