/// <summary> /// 设置通信端口的参数 /// </summary> private void SetCOMMSerialPortParam() { if ((this.m_COMMComboBox.Text != null) && (this.m_COMMComboBox.Items.Count > 0)) { COMMSerialPortParamForm p = new COMMSerialPortParamForm(this.m_COMMComboBox.Text, this.m_COMMSerialPortParam); if (p.ShowDialog(this.m_COMMComboBox) != System.Windows.Forms.DialogResult.OK) { if (this.m_COMMRichTextBox != null) { RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.m_COMMRichTextBox, "通信端口参数配置失败。\r\n", Color.Red, false); } } else { this.m_COMMSerialPortParam = ((COMMSerialPortParamForm)p).m_COMMSerialPortParam; if (this.m_COMMRichTextBox != null) { RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.m_COMMRichTextBox, "通信端口参数配置成功。\r\n", Color.Black, false); } p.CloseForm(); } } }
/// <summary> /// 设置参数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void COMMSerialPortParam_Click(object sender, EventArgs e) { if ((this.m_COMMComboBox.Text != null) && (this.m_COMMComboBox.Items.Count > 0)) { COMMSerialPortParamForm p = new COMMSerialPortParamForm(this.m_COMMComboBox.Text); if (p.ShowDialog(this.m_COMMComboBox) != System.Windows.Forms.DialogResult.OK) { if (this.m_COMMRichTextBox != null) { RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.m_COMMRichTextBox, "通信端口参数配置失败。\r\n", Color.Red, false); } return; } this.m_COMMSerialPortParam = ((COMMSerialPortParamForm)p).m_COMMSerialPortParam; if (this.m_COMMRichTextBox != null) { RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.m_COMMRichTextBox, "通信端口参数配置成功。\r\n", Color.Black, false); } p.CloseForm(); } }
/// <summary> /// /// </summary> /// <param name="argName"></param> /// <param name="commSerialPortParam"></param> public COMMSerialPortParamForm(string argName, COMMSerialPortParam commSerialPortParam) { InitializeComponent(); //---限定最小尺寸 this.MinimumSize = this.Size; this.MaximumSize = this.Size; //--- this.Init(argName, commSerialPortParam); }
/// <summary> /// /// </summary> /// <param name="argName"></param> public virtual void Init(string argName, COMMSerialPortParam commSerialPortParam) { this.Init(argName); if (commSerialPortParam == null) { return; } //---波特率 int index = this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortBaudRate.Items.IndexOf(commSerialPortParam.baudRate); if (index < 0) { this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortBaudRate.Items.Add(commSerialPortParam.baudRate); this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortBaudRate.SelectedIndex = this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortBaudRate.Items.Count - 1; } else { this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortBaudRate.SelectedIndex = index; } //---数据位 index = this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortDataBits.Items.IndexOf(commSerialPortParam.dataBits); if (index < 0) { this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortDataBits.SelectedIndex = 0; } else { this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortDataBits.SelectedIndex = index; } //---停止位 index = this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortStopBits.Items.IndexOf(commSerialPortParam.stopBits); if (index < 0) { this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortStopBits.SelectedIndex = 0; } else { this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortStopBits.SelectedIndex = index; } //---校验位 index = this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortParity.Items.IndexOf(commSerialPortParam.parity); if (index < 0) { this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortParity.SelectedIndex = 0; } else { this.commSerialPortPlusFullParam.m_ComboBoxCOMMPortParity.SelectedIndex = index; } }
/// <summary> /// /// </summary> /// <param name="commSerialPortParam"></param> public void Init(COMMSerialPortParam commSerialPortParam) { if (commSerialPortParam == null) { return; } int index = this.comboBox_COMMPortBaudRate.Items.IndexOf(commSerialPortParam.baudRate); if (index < 0) { this.comboBox_COMMPortBaudRate.SelectedIndex = 0; if (comboBox_COMMPortBaudRate.DropDownStyle != System.Windows.Forms.ComboBoxStyle.DropDown) { comboBox_COMMPortBaudRate.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown; } } this.comboBox_COMMPortBaudRate.Text = commSerialPortParam.baudRate; }
/// <summary> /// /// </summary> /// <param name="commSerialPortParam"></param> /// <param name="msg"></param> public COMMBasePort(Form argForm, COMMSerialPortParam commSerialPortParam, RichTextBox msg) { }
/// <summary> /// /// </summary> /// <param name="bandRate"></param> /// <param name="msg"></param> public COMMBasePort(COMMSerialPortParam commSerialPortParam, RichTextBox msg) { }
/// <summary> /// /// </summary> /// <param name="argName"></param> /// <param name="msg"></param> /// <returns></returns> public virtual int OpenDevice(COMMSerialPortParam commSerialPortParam, RichTextBox msg = null) { return(1); }
/// <summary> /// /// </summary> /// <param name="argName"></param> /// <param name="commSerialPortParam"></param> /// <param name="msg"></param> /// <returns></returns> public virtual int Init(COMMSerialPortParam commSerialPortParam, RichTextBox msg = null) { return(1); }