Ejemplo n.º 1
0
 private void CutTest_BTN_Click(object sender, EventArgs e)
 {
     try
     {
         CutTest_BTN.Enabled = false;
         CutTest_BTN.Update();
         MainSerialPort.WriteLine("C");
         stopwatch.Reset();
         stopwatch.Start();
         while (stopwatch.ElapsedMilliseconds < 1000)
         {
         }
         stopwatch.Stop();
         Application.DoEvents();
         if (!CutTest_BTN.IsDisposed)
         {
             CutTest_BTN.Enabled = true;
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Error - connection problem");
         CutTest_BTN.Enabled = true;
     }
 }
Ejemplo n.º 2
0
        private void Connect_BTN_Click(object sender, EventArgs e)
        {
            if (Connect_BTN.Text.Equals("Connect"))
            {
                try
                {
                    Connect_BTN.Enabled      = false;
                    MainSerialPort.BaudRate  = 9600;
                    MainSerialPort.PortName  = comboBox1.Text;
                    MainSerialPort.NewLine   = "\r\n";
                    MainSerialPort.DtrEnable = true;
                    stopwatch.Reset();
                    stopwatch.Start();
                    MainSerialPort.Open();
                    while (stopwatch.ElapsedMilliseconds < 1000)
                    {
                    }
                    stopwatch.Stop();
                    //Thread.Sleep(1000);
                    MessageBox.Show("Connected");
                    FunctionsEnableConnection();
                    Connect_BTN.Enabled = true;
                }

                catch (Exception)
                {
                    MessageBox.Show("Error - connection problem!");
                    Connect_BTN.Enabled = true;
                }
            }
            else if (Connect_BTN.Text.Equals("Disconnect"))
            {
                try
                {
                    Connect_BTN.Enabled = false;
                    MainSerialPort.WriteLine("E");
                    MainSerialPort.DiscardInBuffer();
                    MainSerialPort.DiscardOutBuffer();
                    MainSerialPort.BaseStream.Flush();
                    stopwatch.Reset();
                    stopwatch.Start();
                    while (stopwatch.ElapsedMilliseconds < 1000)
                    {
                    }
                    stopwatch.Stop();
                    Connect_BTN.Enabled = true;
                }
                catch (Exception)
                {
                    Connect_BTN.Enabled = true;
                }
                MainSerialPort.Close();
                FunctionsBase();
            }
        }
Ejemplo n.º 3
0
 private void Read_BTN_Click(object sender, EventArgs e)
 {
     try
     {
         Read_BTN.Enabled = false;
         MainSerialPort.WriteLine("R");
         stopwatch.Reset();
         stopwatch.Start();
         while (stopwatch.ElapsedMilliseconds < 1000)
         {
         }
         stopwatch.Stop();
         Read_BTN.Enabled = true;
     }
     catch (Exception)
     {
         MessageBox.Show("Error - connection problem");
         Read_BTN.Enabled = true;
     }
 }
Ejemplo n.º 4
0
 private void SerialDataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
 {
     IncomingData = MainSerialPort.ReadLine();
     Invoke(new EventHandler(ReceivedDataHandle));
 }