⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 settingsform.cs

📁 C#串口编程。详细讲解
💻 CS
📖 第 1 页 / 共 3 页
字号:
			this.label4.Location = new System.Drawing.Point(8, 40);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(64, 16);
			this.label4.TabIndex = 9;
			this.label4.Text = "DataBits";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.toolTip.SetToolTip(this.label4, "Number of data bits in the frame (unsupported values will throw an exception)");
			// 
			// groupBox4
			// 
			this.groupBox4.Controls.Add(this.label9);
			this.groupBox4.Controls.Add(this.label8);
			this.groupBox4.Controls.Add(this.comboBoxXoff);
			this.groupBox4.Controls.Add(this.comboBoxXon);
			this.groupBox4.Location = new System.Drawing.Point(4, 303);
			this.groupBox4.Name = "groupBox4";
			this.groupBox4.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
			this.groupBox4.Size = new System.Drawing.Size(288, 48);
			this.groupBox4.TabIndex = 21;
			this.groupBox4.TabStop = false;
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(149, 18);
			this.label9.Name = "label9";
			this.label9.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.label9.Size = new System.Drawing.Size(64, 16);
			this.label9.TabIndex = 28;
			this.label9.Text = "Xoff Code";
			this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip.SetToolTip(this.label9, "ASCII code to use for Xoff signal");
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(8, 18);
			this.label8.Name = "label8";
			this.label8.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.label8.Size = new System.Drawing.Size(64, 16);
			this.label8.TabIndex = 27;
			this.label8.Text = "Xon Code";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip.SetToolTip(this.label8, "ASCII code to use for Xon signal");
			// 
			// comboBoxXoff
			// 
			this.comboBoxXoff.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBoxXoff.Location = new System.Drawing.Point(219, 16);
			this.comboBoxXoff.Name = "comboBoxXoff";
			this.comboBoxXoff.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.comboBoxXoff.Size = new System.Drawing.Size(56, 21);
			this.comboBoxXoff.TabIndex = 26;
			this.toolTip.SetToolTip(this.comboBoxXoff, "ASCII code to use for Xoff signal");
			// 
			// comboBoxXon
			// 
			this.comboBoxXon.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBoxXon.Location = new System.Drawing.Point(75, 16);
			this.comboBoxXon.Name = "comboBoxXon";
			this.comboBoxXon.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.comboBoxXon.Size = new System.Drawing.Size(56, 21);
			this.comboBoxXon.TabIndex = 25;
			this.toolTip.SetToolTip(this.comboBoxXon, "ASCII code to use for Xon signal");
			// 
			// checkBoxAR
			// 
			this.checkBoxAR.Location = new System.Drawing.Point(156, 280);
			this.checkBoxAR.Name = "checkBoxAR";
			this.checkBoxAR.Size = new System.Drawing.Size(96, 16);
			this.checkBoxAR.TabIndex = 22;
			this.checkBoxAR.Text = "Auto re-open";
			this.toolTip.SetToolTip(this.checkBoxAR, "Automatically reopen port if it closes due to an error");
			// 
			// groupBox5
			// 
			this.groupBox5.Controls.Add(this.label18);
			this.groupBox5.Controls.Add(this.label10);
			this.groupBox5.Controls.Add(this.checkBoxBLC);
			this.groupBox5.Controls.Add(this.comboBoxBRK);
			this.groupBox5.Controls.Add(this.checkBoxHX);
			this.groupBox5.Controls.Add(this.numericUpDownBRN);
			this.groupBox5.Location = new System.Drawing.Point(4, 352);
			this.groupBox5.Name = "groupBox5";
			this.groupBox5.Size = new System.Drawing.Size(288, 96);
			this.groupBox5.TabIndex = 23;
			this.groupBox5.TabStop = false;
			this.groupBox5.Text = "Display";
			// 
			// label18
			// 
			this.label18.Location = new System.Drawing.Point(200, 64);
			this.label18.Name = "label18";
			this.label18.Size = new System.Drawing.Size(56, 16);
			this.label18.TabIndex = 27;
			this.label18.Text = "chars.";
			this.label18.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(16, 65);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(128, 16);
			this.label10.TabIndex = 26;
			this.label10.Text = "Break line every";
			this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip.SetToolTip(this.label10, "Break line when it reaches this length (0 - do not break)");
			// 
			// checkBoxBLC
			// 
			this.checkBoxBLC.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.checkBoxBLC.Location = new System.Drawing.Point(13, 40);
			this.checkBoxBLC.Name = "checkBoxBLC";
			this.checkBoxBLC.Size = new System.Drawing.Size(152, 16);
			this.checkBoxBLC.TabIndex = 25;
			this.checkBoxBLC.Text = "Break line on ASCII char";
			this.checkBoxBLC.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip.SetToolTip(this.checkBoxBLC, "Break displayed lines after specified character");
			// 
			// comboBoxBRK
			// 
			this.comboBoxBRK.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBoxBRK.Location = new System.Drawing.Point(176, 37);
			this.comboBoxBRK.Name = "comboBoxBRK";
			this.comboBoxBRK.Size = new System.Drawing.Size(56, 21);
			this.comboBoxBRK.TabIndex = 24;
			this.toolTip.SetToolTip(this.comboBoxBRK, "The character after which the line is broken");
			// 
			// checkBoxHX
			// 
			this.checkBoxHX.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.checkBoxHX.Location = new System.Drawing.Point(13, 16);
			this.checkBoxHX.Name = "checkBoxHX";
			this.checkBoxHX.Size = new System.Drawing.Size(152, 16);
			this.checkBoxHX.TabIndex = 23;
			this.checkBoxHX.Text = "Display in hexadecimal";
			this.checkBoxHX.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip.SetToolTip(this.checkBoxHX, "Display received characters as two hexadecimal digits");
			// 
			// numericUpDownBRN
			// 
			this.numericUpDownBRN.Location = new System.Drawing.Point(151, 64);
			this.numericUpDownBRN.Maximum = new System.Decimal(new int[] {
																			 255,
																			 0,
																			 0,
																			 0});
			this.numericUpDownBRN.Name = "numericUpDownBRN";
			this.numericUpDownBRN.Size = new System.Drawing.Size(48, 20);
			this.numericUpDownBRN.TabIndex = 19;
			this.toolTip.SetToolTip(this.numericUpDownBRN, "Break line when it reaches this length (0 - do not break)");
			// 
			// openFileDialog
			// 
			this.openFileDialog.DefaultExt = "JHC";
			this.openFileDialog.Filter = "JHBaseTerm files|*.JHC|All files|*.*";
			this.openFileDialog.Title = "Open XML Settings File";
			// 
			// saveFileDialog
			// 
			this.saveFileDialog.DefaultExt = "JHC";
			this.saveFileDialog.Filter = "JHBaseTerm files|*.JHC|All files|*.*";
			this.saveFileDialog.Title = "Save XML Settings File";
			// 
			// SettingsForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(294, 451);
			this.Controls.Add(this.groupBox5);
			this.Controls.Add(this.checkBoxAR);
			this.Controls.Add(this.groupBox4);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Menu = this.mainMenu1;
			this.Name = "SettingsForm";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "CommBase Settings";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.SettingsForm_Closing);
			this.Load += new System.EventHandler(this.SettingsForm_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.numericUpDownTC)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDownTM)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDownTxS)).EndInit();
			this.groupBox2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.numericUpDownRxS)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDownHW)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDownLW)).EndInit();
			this.groupBox3.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.groupBox5.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.numericUpDownBRN)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

	private void Import()
	{
		BaseTerm.CommBaseTermSettings s = BaseTerm.settings;

		comboBoxPort.Text = s.port;
		checkBoxAR.Checked = s.autoReopen;
		comboBoxBaud.SelectedIndex = comboBoxBaud.FindString(s.baudRate.ToString());
		comboBoxParity.SelectedIndex = (int)s.parity;
		comboBoxDB.SelectedIndex = comboBoxDB.FindString(s.dataBits.ToString());
		comboBoxSB.SelectedIndex = (int)s.stopBits;
		checkBoxCTS.Checked = s.txFlowCTS;
		checkBoxDSR.Checked = s.txFlowDSR;
		checkBoxTxX.Checked = s.txFlowX;
		checkBoxXC.Checked = s.txWhenRxXoff;
		comboBoxRTS.SelectedIndex = (int)s.useRTS;
		comboBoxDTR.SelectedIndex = (int)s.useDTR;
		checkBoxRxX.Checked = s.rxFlowX;
		checkBoxGD.Checked = s.rxGateDSR;
		comboBoxXon.SelectedIndex = (int)s.XonChar;
		comboBoxXoff.SelectedIndex = (int)s.XoffChar;
		numericUpDownTM.Value = s.sendTimeoutMultiplier;
		numericUpDownTC.Value = s.sendTimeoutConstant;
		numericUpDownLW.Value = s.rxLowWater;
		numericUpDownHW.Value = s.rxHighWater;
		numericUpDownRxS.Value = s.rxQueue;
		checkBoxCheck.Checked = s.checkAllSends;
		numericUpDownTxS.Value = s.txQueue;
		checkBoxBLC.Checked = s.breakLineOnChar;
		comboBoxBRK.SelectedIndex = (int)s.lineBreakChar;
		numericUpDownBRN.Value = s.charsInLine;
		checkBoxHX.Checked = s.showAsHex;
	}

	private void Export()
	{
		BaseTerm.CommBaseTermSettings s = BaseTerm.settings;

		s.port = comboBoxPort.Text;
		s.autoReopen = checkBoxAR.Checked;
		s.baudRate = int.Parse(comboBoxBaud.Text);
		s.parity = (CommBase.Parity)comboBoxParity.SelectedIndex;
		s.dataBits = int.Parse(comboBoxDB.Text);
		s.stopBits = (CommBase.StopBits)comboBoxSB.SelectedIndex;
		s.txFlowCTS = checkBoxCTS.Checked;
		s.txFlowDSR = checkBoxDSR.Checked;
		s.txFlowX = checkBoxTxX.Checked;
		s.txWhenRxXoff = checkBoxXC.Checked;
		s.useRTS = (CommBase.HSOutput)comboBoxRTS.SelectedIndex;
		s.useDTR = (CommBase.HSOutput)comboBoxDTR.SelectedIndex;
		s.rxFlowX = checkBoxRxX.Checked;
		s.rxGateDSR = checkBoxGD.Checked;
		s.XonChar = (CommBase.ASCII)comboBoxXon.SelectedIndex;
		s.XoffChar = (CommBase.ASCII)comboBoxXoff.SelectedIndex;
		s.sendTimeoutMultiplier = (uint)numericUpDownTM.Value;
		s.sendTimeoutConstant = (uint)numericUpDownTC.Value;
		s.rxLowWater = (int)numericUpDownLW.Value;
		s.rxHighWater = (int)numericUpDownHW.Value;
		s.rxQueue = (int)numericUpDownRxS.Value;
		s.txQueue = (int)numericUpDownTxS.Value;
		s.checkAllSends = checkBoxCheck.Checked;
		s.breakLineOnChar = checkBoxBLC.Checked;
		s.lineBreakChar = (CommBase.ASCII)comboBoxBRK.SelectedIndex;
		s.charsInLine = (int)numericUpDownBRN.Value;
		s.showAsHex = checkBoxHX.Checked;
	}

	private void FillASCII(ComboBox cb)
	{
		CommBase.ASCII asc;
		for (int i=0; (i < 256); i++)
		{
			asc = (CommBase.ASCII)i;
			if ((i < 33) || (i > 126))
				cb.Items.Add(asc.ToString());
			else
				cb.Items.Add(new string((char)i, 1));
		}
	}

	private void FillPorts(ComboBox cb)
	{
		string n;
		for (int i=0; (i < 99); i++)
		{
			n = "COM" + i.ToString();
			if (BaseTerm.term.IsPortAvailable(n) == CommBase.PortStatus.available)
			{
				cb.Items.Add(n);
			}
		}
	}

	private void SettingsForm_Load(object sender, System.EventArgs e)
	{
		Import();
	}

	private void SettingsForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
	{
		Export();
	}

	private void menuItemHSN_Click(object sender, System.EventArgs e)
	{
		BaseTerm.settings.SetStandard(comboBoxPort.Text, int.Parse(comboBoxBaud.Text), CommBase.Handshake.none);
		Import();
	}

	private void menuItemHSX_Click(object sender, System.EventArgs e)
	{
		BaseTerm.settings.SetStandard(comboBoxPort.Text, int.Parse(comboBoxBaud.Text), CommBase.Handshake.XonXoff);
		Import();
	}

	private void menuItemHSC_Click(object sender, System.EventArgs e)
	{
		BaseTerm.settings.SetStandard(comboBoxPort.Text, int.Parse(comboBoxBaud.Text), CommBase.Handshake.CtsRts);
		Import();
	}

	private void menuItemHSD_Click(object sender, System.EventArgs e)
	{
		BaseTerm.settings.SetStandard(comboBoxPort.Text, int.Parse(comboBoxBaud.Text), CommBase.Handshake.DsrDtr);
		Import();
	}

	private void menuItemClose_Click(object sender, System.EventArgs e)
	{
		this.Close();
	}

	private void menuItemSaveXML_Click(object sender, System.EventArgs e)
	{
		if (saveFileDialog.ShowDialog() == DialogResult.OK)
		{
			Export();
			BaseTerm.settings.SaveAsXML(saveFileDialog.OpenFile());
		}
	}

	private void menuItemOpenXML_Click(object sender, System.EventArgs e)
	{
		if (openFileDialog.ShowDialog() == DialogResult.OK)
		{
			BaseTerm.CommBaseTermSettings ss = BaseTerm.CommBaseTermSettings.LoadFromXML(openFileDialog.OpenFile());
			if (ss != null)
			{
				BaseTerm.settings = ss;
				Import();
			}
			else
			{
				MessageBox.Show("Error opening XML settings file", "BaseTerm", MessageBoxButtons.OK);
			}
		}
	}

	private void comboBoxPort_DropDown(object sender, System.EventArgs e)
	{
		if (comboBoxPort.Items.Count < 1) FillPorts(comboBoxPort);	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -