private void COM2_DataReceived(object sender, SerialDataReceivedEventArgs e) { Thread.Sleep(100); // important string from_bs_2_t = COM2.ReadExisting(); showdata_2(from_bs_2_t); }
// automatic running // /* private void pTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { string[] lines_sensor = System.IO.File.ReadAllLines(korea); int which_channel = 0; if (lines_sensor.Length != 0) { if (initial_changdu != lines_sensor.Length) { if (lines_sensor[lines_sensor.Length - 1].Contains("+")) { //eg:1+T-2-1 第一channel,第二个meter,关 string [] zhong = lines_sensor[lines_sensor.Length - 1].Split('+'); which_channel = Convert.ToInt32(zhong[0]); textBox12.Text = zhong[1]; if ((COM1.IsOpen) && (which_channel == 1)) { COM1.Write(zhong[1]); COM1.DiscardOutBuffer(); order_record(zhong[1]); } else if ((COM2.IsOpen) && (which_channel == 2)) { COM2.Write(zhong[1]); COM2.DiscardOutBuffer(); order_record_2(zhong[1]); } } } } GC.Collect(); initial_changdu = lines_sensor.Length; }
private void button11_Click(object sender, EventArgs e) { if (COM2.IsOpen) { COM2.Close(); progressBar6.Value = 0; } }
private void button1_Click(object sender, EventArgs e) { if (COM2.IsOpen) { string output; output = textBox8.Text; COM2.Write(output); textBox8.Text = ""; COM2.DiscardOutBuffer(); order_record_2(output); } }
private void button12_Click(object sender, EventArgs e) { try { COM2.PortName = comboBox9.Text; COM2.BaudRate = 9600; COM2.DataBits = 8; COM2.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "One"); COM2.Parity = (Parity)Enum.Parse(typeof(Parity), "None"); COM2.Open(); progressBar6.Value = 100; } catch (Exception err) { MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }