windows下串口的设置问题
发布日期:2021-05-07 00:06:36 浏览次数:27 分类:精选文章

本文共 932 字,大约阅读时间需要 3 分钟。

              根据微软的规定,Windows串口数据位数必须为5到8,使用5个数据位和2个停止位是非法的组合。同样,使用6、7、8个数据位和1.5个停止位也是非法的。当使用5个数据位时,可以使用1或1.5个停止位。使用其它数据位选项(6,7,8)时,只能使用1或2个停止位.

         来自http://www.eleok.com/thread-86448-1-1.html
         自己用c#编了一个简单的串口程序,用虚拟串口测试了一下 不按上面的规定是无法打开串口的
SerialPort s;        public Form1()        {            InitializeComponent();            try            {                //串口 名字 波特率 有无校验 停止位                s = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);                s.DataReceived += new SerialDataReceivedEventHandler(s_DataReceived);                s.Open();            }            catch            {                MessageBox.Show("串口打开失败");            }        }        void s_DataReceived(object sender, SerialDataReceivedEventArgs e)        {            jieshou.AppendText(s.ReadLine());        }        //这是一个button的点击函数        private void bt_Click(object sender, EventArgs e)        {            s.WriteLine(fasong.Text);         }
上一篇:proteus原理图转化为pcb
下一篇:c#Invoke和BeginInvoke的区别

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2025年03月24日 17时38分22秒