private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (COM4.IsOpen) { COM4.Close(); } }
private void com4_open_Click(object sender, EventArgs e) { try { if (!COM4.IsOpen) { COM4.Open(); } status.Text = "открыт"; } catch (System.IO.IOException) { status.Text = "ошибка"; MessageBox.Show("НЕТ"); } }
private void button2_Click(object sender, EventArgs e) { try { if (COM4.IsOpen) { COM4.Close(); } status.Text = "закрыт"; } catch (System.IO.IOException) { status.Text = "ошибка"; MessageBox.Show("НЕТ"); } }
private void DoUpdate(object s, EventArgs e) { string message = COM4.ReadExisting(); string datamsg; GraphPane pane = Graph.GraphPane; pane.CurveList.Clear(); //!!!!!!!!! try { // adc.Text += "event\n"; number.Text = message.Length.ToString(); adc.Text += message[0]; adc.Text += " "; adc.Text += message[message.Length - 2]; adc.Text += "\n"; string firstbyte = "#"; string lastbyte = "&"; if (message[0] == firstbyte.ToCharArray()[0] && message[message.Length - 2] == lastbyte.ToCharArray()[0]) { datamsg = message.Substring(2, message.Length - 6); yn.Text += datamsg; yn.Text += "\n"; string splitstring = " \n\r "; strarr = datamsg.Split(splitstring.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); try { data.Add(Int32.Parse(strarr[0]), Int32.Parse(strarr[1])); filtereddata.Add(Int32.Parse(strarr[0]), Int32.Parse(strarr[2])); } catch (FormatException) { } LineItem data_Curve = pane.AddCurve("adc_data", data, Color.Blue, SymbolType.None); LineItem filter_myCurve = pane.AddCurve("filtered_data", filtereddata, Color.Red, SymbolType.None); Graph.AxisChange(); Graph.Invalidate(); counter.Text += "a="; counter.Text += strarr[0]; counter.Text += " "; counter.Text += "b="; counter.Text += strarr[1]; counter.Text += " "; counter.Text += "c="; counter.Text += strarr[2]; counter.Text += " "; counter.Text += "d\n"; counter.Text += strarr[3]; counter.Text += "\n"; } } catch (IndexOutOfRangeException) { // throw; } textbox.Text += message; textbox.Text += "_____\n"; }