예제 #1
0
 private void ButtonCapture_Click(object sender, EventArgs e)
 {
     _spManager.SendData(StopCmd);
     _spManager.SendData(StopCmd);
     _spManager.Dispose();
     _spManager.Dispose();
     _spManager.Dispose();
     _spManager.StartListening();
     TextBoxRawData.Clear();
     sendCmd();
 }
예제 #2
0
 private void ButtonStart_Click(object sender, EventArgs e)
 {
     try
     {
         if (Connected == false)
         {
             _spManager.StartListening();
             sendCmd();
             ComboboxCOM.Enabled  = false;
             LabelConnect.Text    = "ĐÃ KẾT NỐI THIẾT BỊ";
             ButtonStartStop.Text = "NGẮT";
             Connected            = true;
             ButtonStartStop.Focus();
             ButtonCapture.Enabled = true;
             ButtonSave.Enabled    = true;
         }
         else
         {
             _spManager.SendData(StopCmd);
             _spManager.SendData(StopCmd);
             _spManager.SendData(StopCmd);
             _spManager.StopListening();
             _spManager.Dispose();
             _spManager.Dispose();
             _spManager.Dispose();
             TextBoxRawData.Clear();
             ComboboxCOM.Enabled   = true;
             LabelConnect.Text     = "CHƯA KẾT NỐI";
             ButtonStartStop.Text  = "KẾT NỐI";
             ButtonCapture.Text    = "LẤY MẪU";
             Connected             = false;
             ButtonCapture.Enabled = false;
             ButtonSave.Enabled    = false;
         }
         ButtonCapture.Focus();
     }
     catch (Exception ex)
     {
         MetroMessageBox.Show(this, "\r\n\r\nKhông kết nối được với cổng COM :\r\n" + ex.Message, "Thử lại", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
예제 #3
0
        void _spManager_NewSerialDataRecieved(object sender, SerialDataEventArgs e)
        {
            if (this.InvokeRequired)
            {
                // Using this.Invoke causes deadlock when closing serial port, and BeginInvoke is good practice anyway.
                this.BeginInvoke(new EventHandler <SerialDataEventArgs>(_spManager_NewSerialDataRecieved), new object[] { sender, e });
                return;
            }
            // This application is connected to a GPS sending ASCCI characters, so data is converted to text
            string str = Encoding.ASCII.GetString(e.Data);

            TextBoxRawData.AppendText(str);
            if (TextBoxRawData.TextLength == 4021)
            {
                string[] RawData = TextBoxRawData.Text.Split(',');
                TextBoxRawData.Clear();
                _spManager.Dispose();
                if (RawData.Length > SampleCount * 2)
                {
                    for (int i = 0; i < RawData.Length; i++)
                    {
                        if (i < SampleCount)
                        {
                            UInt16 ADC;
                            if (UInt16.TryParse(RawData[i], out ADC))
                            {
                                ChannelA[i] = ADC;
                            }
                        }
                        if ((i >= SampleCount) && (i < (RawData.Length - 2)))
                        {
                            UInt16 ADC;
                            if (UInt16.TryParse(RawData[i], out ADC))
                            {
                                ChannelB[i - SampleCount] = ADC;
                            }
                        }
                        if (i == (RawData.Length - 2))
                        {
                            if (UInt32.TryParse(RawData[i], out TimerValue))
                            {
                            }
                        }
                        if (i == (RawData.Length - 1))
                        {
                            if (UInt32.TryParse(RawData[i], out SampleRateValue))
                            {
                                DrawScope();
                                if (RadioButtonRepeat.Checked)
                                {
                                    _spManager.clearInBuffer();
                                    _spManager.clearOutBuffer();
                                    _spManager.Dispose();
                                    _spManager.Dispose();
                                    _spManager.Dispose();
                                    _spManager.StartListening();
                                    if ((ToggleA.Checked == true) || (ToggleB.Checked == true))
                                    {
                                        sendCmd();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }