Ejemplo n.º 1
0
        private void Do_connect()
        {
            if (!isConnected)
            {
                string selectedPort = "";
                int    baudr        = 0;
                isConnected = true;
                if (AvailableSerialPorts.GetItemText(AvailableSerialPorts.SelectedItem) != "")
                {
                    selectedPort = AvailableSerialPorts.GetItemText(AvailableSerialPorts.SelectedItem);
                }
                if (Cmbaudr.GetItemText(Cmbaudr.SelectedItem) != "")
                {
                    baudr = Int32.Parse(Cmbaudr.GetItemText(Cmbaudr.SelectedItem));
                }

                if ((selectedPort != "") && (baudr != 0))
                {
                    if (SerialPort.GetPortNames().ToList().Contains(selectedPort))
                    {
                        Properties.Settings.Default.baurdr  = Cmbaudr.GetItemText(Cmbaudr.SelectedItem);
                        Properties.Settings.Default.ComPort = selectedPort;
                        DserialPort1.PortName = selectedPort;
                        DserialPort1.BaudRate = baudr;
                        if (DserialPort1.IsOpen == false)
                        {
                            try
                            {
                                DserialPort1.Open();
                            }
                            catch (Exception)
                            {
                                label2.Text = "Port in use!";
                            }
                        }
                    }
                }
            }
            else
            {
                isConnected = false;
                ;// well shit
                DserialPort1.Close();
            }
        }
Ejemplo n.º 2
0
 private void PHeatingSystem_FormClosing(object sender, FormClosingEventArgs e)
 {
     DserialPort1.Close();
 }
Ejemplo n.º 3
0
 private void Form2_FormClosed(object sender, FormClosedEventArgs e)
 {
     DserialPort1.Close();
     Properties.Settings.Default.Save();
 }
Ejemplo n.º 4
0
 private void Bdissconect_Click(object sender, EventArgs e)
 {
     isConnected = false;
     ;// well shit
     DserialPort1.Close();
 }