110,538
社区成员
发帖
与我相关
我的任务
分享
// 摘要:
// 指定在 System.IO.Ports.SerialPort 对象上使用的停止位的数目。
public enum StopBits
{
// 摘要:
// 不使用停止位。 System.IO.Ports.SerialPort.StopBits 属性不支持此值。
None = 0,
//
// 摘要:
// 使用一个停止位。
One = 1,
//
// 摘要:
// 使用两个停止位。
Two = 2,
//
// 摘要:
// 使用 1.5 个停止位。
OnePointFive = 3,
}
public void OpenPort()
{
if (comPort.IsOpen)
comPort.Close();
comPort.PortName = _portName;
comPort.BaudRate = (int)19200;
comPort.Parity = Parity.None;
comPort.DataBits = (int)8;
comPort.StopBits = StopBits.OnePointFive;
try
{
comPort.Open();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
comPort.StopBits = (StopBits)1.5;
程序可以正常运行,我想是不是MSDN中存在某些bug,还是我忽略了什么,来来来,总得有个人接分using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public SerialPort comPort = new SerialPort();//初始化端口类对象
private void button1_Click(object sender, EventArgs e)
{
if (comPort.IsOpen)
comPort.Close();
comPort.PortName = "COM9";
comPort.BaudRate = (int)19200;
comPort.Parity = Parity.None;
comPort.DataBits = (int)8;
comPort.StopBits = StopBits.OnePointFive;
try
{
comPort.Open();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Form1_Load()
{
}
}
}