private void button3_Click(object sender, EventArgs e) { try { //数字源串口 iniFileTool.iniPath = System.Windows.Forms.Application.StartupPath + "\\Config.ini"; String comPortName = iniFileTool.ReadIniData("Digital", "串口", "COM2"); int baudRate = int.Parse(iniFileTool.ReadIniData("Digital", "波特率", "57600")); string parity = iniFileTool.ReadIniData("Digital", "校验位", "None"); int dataBits = int.Parse(iniFileTool.ReadIniData("Digital", "数据位", "8")); string StopBits = iniFileTool.ReadIniData("Digital", "停止位", "2"); if (DPower_Serial.setSerialPort(comPortName, baudRate, parity, dataBits, StopBits) == false) { RTB_Digital.AppendText("打开数字源通讯端口失败!!" + "\r\n"); return; } else { RTB_Digital.AppendText("打开数字源通讯端口成功" + "\r\n"); } //物理串口 comPortName = iniFileTool.ReadIniData("Physical", "串口", "COM1"); baudRate = int.Parse(iniFileTool.ReadIniData("Physical", "波特率", "57600")); parity = iniFileTool.ReadIniData("Physical", "校验位", "None"); dataBits = int.Parse(iniFileTool.ReadIniData("Physical", "数据位", "8")); StopBits = iniFileTool.ReadIniData("Physical", "停止位", "2"); if (Physical_Serial.setSerialPort(comPortName, baudRate, parity, dataBits, StopBits) == false) { RTB_Physical.AppendText("打开上行物理通讯端口失败!!" + "\r\n"); return; } else { RTB_Physical.AppendText("打开上行物理通讯端口成功" + "\r\n"); } m_timerCmdSendPower = new System.Threading.Timer(new TimerCallback(Comunication), null, 600, 500);//500ms } catch (Exception exc) { MessageBox.Show(exc.ToString()); } }
private void button4_Click(object sender, EventArgs e) { RTB_Digital.Clear(); RTB_Physical.Clear(); }