最简单的串口通信上位机(VS2019 C#)
最基本的页面:
这里用了两个groupBox,这样就可以在两个页面分别用radioButton了。
部分代码介绍:
首先是 打开串口 按钮的代码:
private void Button_com_Click(object sender, EventArgs e)
{
try
{
if (!s.IsOpen )
{
button_send.Enabled = true; //打开串口的同时让send按钮可用
//SerialPort s = new SerialPort(); 这是在之前定义的
s.PortName = comboBox_com_selsct.SelectedItem.ToString();
s.BaudRate = Convert.ToInt32(comboBox_baud_select.SelectedItem.ToString()); // 获取或设置串行波特率。
s.Open();
s.DataReceived += s_DataReceived;
button_com.Text = "关闭串口";
}
else
{
button_com.Text = "打开串口";
s.Close();
}
}
catch (Exception ee)
{