Пример #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();
            }
        }
Пример #2
0
 private void PHeatingSystem_FormClosing(object sender, FormClosingEventArgs e)
 {
     DserialPort1.Close();
 }
Пример #3
0
 private void Form2_FormClosed(object sender, FormClosedEventArgs e)
 {
     DserialPort1.Close();
     Properties.Settings.Default.Save();
 }
Пример #4
0
        private void DserialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                string inputData;
                inputData = DserialPort1.ReadLine();
                //textBox1.BeginInvoke(new Action(() => { textBox1.Text += inputData; }));
                //textBox1.BeginInvoke(new Action(() => { textBox1.Text += "\n\r"; }));
                bool     canConvert;
                string[] indata1 = inputData.Split(':');
                //well i forgot but i think this inputs the data from the module
                if (Properties.Settings.Default.GsensorID1 == indata1[0])
                {
                    Properties.Settings.Default.GsensorID1 = indata1[1];
                    GsensorID1.BeginInvoke(new Action(() => { GsensorID1.Text = indata1[1]; }));
                }
                if (Properties.Settings.Default.GsensorID2 == indata1[0])
                {
                    Properties.Settings.Default.GsensorID2 = indata1[1];
                    GsensorID2.BeginInvoke(new Action(() => { GsensorID2.Text = indata1[1]; }));
                }
                if (Properties.Settings.Default.GsensorID3 == indata1[0])
                {
                    Properties.Settings.Default.GsensorID3 = indata1[1];
                    GsensorID3.BeginInvoke(new Action(() => { GsensorID3.Text = indata1[1]; }));
                }
                if (Properties.Settings.Default.GsensorID4 == indata1[0])
                {
                    Properties.Settings.Default.GsensorID4 = indata1[1];
                    GsensorID4.BeginInvoke(new Action(() => { GsensorID4.Text = indata1[1]; }));
                }
                if (Properties.Settings.Default.GsensorID5 == indata1[0])
                {
                    Properties.Settings.Default.GsensorID5 = indata1[1];
                    GsensorID5.BeginInvoke(new Action(() => { GsensorID5.Text = indata1[1]; }));
                }
                if (Properties.Settings.Default.GsensorID6 == indata1[0])
                {
                    Properties.Settings.Default.GsensorID6 = indata1[1];
                    GsensorID6.BeginInvoke(new Action(() => { GsensorID6.Text = indata1[1]; }));
                }

                // code for gauge update
                if (Properties.Settings.Default.GsensorID1 == indata1[1])
                {
                    canConvert = float.TryParse(indata1[2], out float number2);
                    if (canConvert == true)
                    {
                        aGauge1.BeginInvoke(new Action(() => { aGauge1.Value = number2; }));
                    }
                    Agauge1_temp.BeginInvoke(new Action(() => { Agauge1_temp.Text = indata1[2]; }));
                    //Tlabel0.BeginInvoke(new Action(() => { Tlabel0.Text = inputData; }));
                    aGauge1T = V;
                }
                else if (Properties.Settings.Default.GsensorID2 == indata1[1])
                {
                    canConvert = float.TryParse(indata1[2], out float number2);
                    if (canConvert == true)
                    {
                        aGauge2.BeginInvoke(new Action(() => { aGauge2.Value = number2; }));
                    }
                    Agauge2_temp.BeginInvoke(new Action(() => { Agauge2_temp.Text = indata1[2]; }));
                    //Tlabel1.BeginInvoke(new Action(() => { Tlabel1.Text = inputData; }));
                    aGauge2T = V;
                }
                else if (Properties.Settings.Default.GsensorID3 == indata1[1])
                {
                    canConvert = float.TryParse(indata1[2], out float number2);
                    if (canConvert == true)
                    {
                        aGauge3.BeginInvoke(new Action(() => { aGauge3.Value = number2; }));
                    }
                    Agauge3_temp.BeginInvoke(new Action(() => { Agauge3_temp.Text = indata1[2]; }));
                    //Tlabel2.BeginInvoke(new Action(() => { Tlabel2.Text = inputData; }));
                    aGauge3T = V;
                }
                else if (Properties.Settings.Default.GsensorID4 == indata1[1])
                {
                    canConvert = float.TryParse(indata1[2], out float number2);
                    if (canConvert == true)
                    {
                        aGauge4.BeginInvoke(new Action(() => { aGauge4.Value = number2; }));
                    }
                    Agauge4_temp.BeginInvoke(new Action(() => { Agauge4_temp.Text = indata1[2]; }));
                    //Tlabel3.BeginInvoke(new Action(() => { Tlabel3.Text = inputData; }));
                    aGauge4T = V;
                }
                else if (Properties.Settings.Default.GsensorID5 == indata1[1])
                {
                    canConvert = float.TryParse(indata1[2], out float number2);
                    if (canConvert == true)
                    {
                        aGauge5.BeginInvoke(new Action(() => { aGauge5.Value = number2; }));
                    }
                    Agauge5_temp.BeginInvoke(new Action(() => { Agauge5_temp.Text = indata1[2]; }));
                    // Tlabel4.BeginInvoke(new Action(() => { Tlabel4.Text = inputData; }));
                    aGauge5T = V;
                }
                else if (Properties.Settings.Default.GsensorID6 == indata1[1])
                {
                    canConvert = float.TryParse(indata1[2], out float number2);
                    if (canConvert == true)
                    {
                        aGauge6.BeginInvoke(new Action(() => { aGauge6.Value = number2; }));
                    }
                    Agauge6_temp.BeginInvoke(new Action(() => { Agauge6_temp.Text = indata1[2]; }));
                    // Tlabel4.BeginInvoke(new Action(() => { Tlabel4.Text = inputData; }));
                    aGauge6T = V;
                }
            }
            catch (Exception)
            {
                //HandleDisconnect(client);
            }
        }
Пример #5
0
 private void Bdissconect_Click(object sender, EventArgs e)
 {
     isConnected = false;
     ;// well shit
     DserialPort1.Close();
 }