-
Notifications
You must be signed in to change notification settings - Fork 4
/
PortConfigure.cs
92 lines (76 loc) · 2.68 KB
/
PortConfigure.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace CellInfo
{
public partial class PortConfigure : Form
{
internal string portName;
internal int baudRate;
internal string handShake;
internal string parity;
internal int dataBits;
internal string stopBits;
public PortConfigure()
{
InitializeComponent();
PortSet();
}
private void PortSet()
{
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
this.comboBox1.Items.Add(port);
}
this.comboBox1.FormattingEnabled = true;
this.comboBox1.TabIndex = 0;
if (ports.Length > 0)
{
this.comboBox1.SelectedIndex = 0;
}
this.comboBox2.SelectedIndex = 3;
this.comboBox3.SelectedIndex = 0;
this.comboBox4.SelectedIndex = 0;
this.comboBox5.SelectedIndex = 4;
this.comboBox6.SelectedIndex = 0;
}
/// <summary>
/// 单击确定
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//this.comboBox2.SelectedText = comboBox2.Text;
//MainForm Mainfrm = new MainForm();
MainForm.PortStatusLabel = "Port Name:" + portName + "; Baud Rate:" + baudRate + "; Handshake:" + handShake + "; Parity:" + parity + "; Data Bits:" + Convert.ToString(dataBits) + "; Stop Bits:" + stopBits;
this.DialogResult = DialogResult.OK;
this.portName = comboBox1.Text;
this.baudRate = Convert.ToInt32(comboBox2.Text);
this.handShake = comboBox3.Text;
this.parity = comboBox4.Text;
this.dataBits = Convert.ToInt32(comboBox5.Text);
this.stopBits = comboBox6.Text;
this.Close();
}
/// <summary>
/// 单击取消
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}