/// <summary> /// 通讯参数改变则更改相应属性 /// </summary> /// <param name="sender">触发的控件</param> /// <param name="e"></param> private void CommunicationPropertyChange(object sender, EventArgs e) { //IProtocol.PortName = "COM1"; //IProtocol.BaudRate = 2400; Protocol645 p645 = new Protocol645(); if (sender == toolStripTbAddr) { Protocol645.Addr = toolStripTbAddr.Text.PadLeft(12, '0'); //表地址改变,则写入addr } if (sender == toolStripTextBoxPsw) { Protocol645.Psw = toolStripTextBoxPsw.Text.PadLeft(8, '0'); //密码改变,则写入psw } if (sender == toolStripTextBoxOprCode) { Protocol645.OprCode = toolStripTextBoxOprCode.Text.PadLeft(8, '0'); //操作者代码改变,则写入oprcode } if (sender == toolStripComboBoxCom) { IProtocol.PortName = toolStripComboBoxCom.Text; //串口号改变 } if (sender == toolStripComboBoxBps) { IProtocol.BaudRate = int.Parse(toolStripComboBoxBps.Text); //波特率改变 } if (sender == menuItemBps2400) { if (p645.ChangeBaudrate("08")) { IProtocol.BaudRate = 2400; //ComPort.ComportBaudRate = 2400; toolStripComboBoxBps.SelectedIndex = 1; } } if (sender == menuItemBps9600) { if (p645.ChangeBaudrate("20")) { IProtocol.BaudRate = 9600; //ComPort.ComportBaudRate = 9600; toolStripComboBoxBps.SelectedIndex = 3; } } }