private void button_COM_Connect_Click(object sender, EventArgs e) { if (this.serialPort != null) { this.serialPort.Dispose(); this.serialPort = null; } int COMPort = -1; if (!int.TryParse(this.textBox_COMPort.Text, out COMPort)) { MessageBox.Show("The value must be integer!"); } if (COMPort != -1) { try { this.serialPort = new COMClient("COM" + COMPort); this.serialPort.OnDataRecieved += COMport_OnDataRecieved; Properties.Settings.Default.COMPort = COMPort; Properties.Settings.Default.Save(); CommandToLog("Set COM port to: COM" + COMPort); this.StatusLabel.Text = "Connected to COM" + COMPort; } catch { MessageBox.Show("Wrong port name!"); this.StatusLabel.Text = "Not connected"; } } }
private void MainForm_Load(object sender, EventArgs e) { this.New_toolStripButton.Click += newToolStripMenuItem_Click; this.Open_toolStripButton.Click += openToolStripMenuItem_Click; this.Save_toolStripButton.Click += Save_toolStripButton_Click; this.SaveAs_toolStripButton.Click += SaveAs_toolStripButton_Click; this.Delete_toolStripButton.Click += Delete_toolStripButton_Click; this.protocols1.OnProtocolChange += OnProtocolChanging; this.Load_toolStripButton.Click += Load_toolStripButton_Click; this.Run_toolStripButton.Click += ManualControlBtn_Click; this.Stop_toolStripButton.Click += ManualControlBtn_Click; this.button_Info.Click += Button_Info_CLick; CopyrightsLabel.Alignment = ToolStripItemAlignment.Right; this.button_COM_Connect.Click += button_COM_Connect_Click; this.btn_Drain_Open.Click += ManualControlBtn_Click; this.btn_Drain_Closed.Click += ManualControlBtn_Click; this.btn_Valve1_Open.Click += ManualControlBtn_Click; this.btn_Valve1_Closed.Click += ManualControlBtn_Click; this.btn_Valve2_Open.Click += ManualControlBtn_Click; this.btn_Valve2_Closed.Click += ManualControlBtn_Click; this.btn_Valve3_Open.Click += ManualControlBtn_Click; this.btn_Valve3_Closed.Click += ManualControlBtn_Click; this.btn_Valve4_Open.Click += ManualControlBtn_Click; this.btn_Valve4_Closed.Click += ManualControlBtn_Click; this.btn_Valve5_Open.Click += ManualControlBtn_Click; this.btn_Valve5_Closed.Click += ManualControlBtn_Click; this.btn_Valve6_Open.Click += ManualControlBtn_Click; this.btn_Valve6_Closed.Click += ManualControlBtn_Click; this.btn_Valve7_Open.Click += ManualControlBtn_Click; this.btn_Valve7_Closed.Click += ManualControlBtn_Click; this.btn_Valve8_Open.Click += ManualControlBtn_Click; this.btn_Valve8_Closed.Click += ManualControlBtn_Click; int COMPort = Properties.Settings.Default.COMPort; this.textBox_COMPort.Text = COMPort.ToString(); try { this.serialPort = new COMClient("COM" + COMPort); this.serialPort.OnDataRecieved += COMport_OnDataRecieved; CommandToLog("Set COM port to: COM" + COMPort); this.StatusLabel.Text = "Connected to COM" + COMPort; } catch { this.StatusLabel.Text = "Not connected"; } }
private void si_DataReceived(string data) { CommandToLog("{" + string.Format("{0:HH:mm:ss:fff}", DateTime.Now) + "} " + COMClient.TranslateFromESP(data.Trim())); }
private void Button_Info_CLick(object sender, EventArgs e) { string[] ports = COMClient.GetPortNames(); CommandToLog("Avaliable ports: " + string.Join(", ", ports)); }