/// <summary> /// Try to start the serial comm /// </summary> /// <returns>True iff start was successful</returns> public bool Start() { if (!_portDef.TryToOpen()) { return(false); } _serialStream = _portDef.Open(); _serialCallback = ProcessData; _serialStream.BeginRead(_inputBytes, 0, _inputBytes.Length, _serialCallback, _count); ++_count; return(true); }
private void button2_Click(object sender, EventArgs e) { if (m_connected) { button2.Text = "Connect"; m_readTh.Abort(); m_readTh.Join(); m_readTh = null; m_gas.Close(); m_gas.Dispose(); m_gas = null; } else { PortDefinition pd = comboBox1.SelectedItem as PortDefinition; m_gas = pd.Open(); m_readTh = new Thread(new ThreadStart(ReadThread)); m_readTh.Start(); button2.Text = "Disconnect"; } m_connected = !m_connected; }