C#实现把指定数据写入串口
更新时间:2015年06月16日 11:34:37 投稿:junjie
这篇文章主要介绍了C#实现把指定数据写入串口,直接给出示例代码,需要的朋友可以参考下
public static bool WriteToSerialPort(byte[]byteArr) { SerialPort Com = newSerialPort(); try { Com.ReadTimeout = 5000; Com.WriteTimeout = 5000; Com.PortName = "Com1"; Com.BaudRate = 9600; Com.StopBits = StopBits.One; Com.Parity = Parity.None; Com.Open(); Com.Write(byteArr, 0,byteArr.Length); return true; } catch(Exception ex) { return false; } finally { Com.Close(); } }
本例使用的是方法Write(Byte[]buffer, Int32 offset, Int32 count)。该方法使用缓冲区的数据将指定数量的字节写入串行端口。buffer为缓冲区,offset表示从此处开始将字节复制到端口,count表示要写入的字节数。
相关文章
C#中调用DLL时未能加载文件或程序集错误的处理方法(详解)
下面小编就为大家带来一篇C#中调用DLL时未能加载文件或程序集错误的处理方法(详解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-02-02
最新评论