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# 对PDF文档加密、解密(基于Spire.Cloud.SDK for .NET)
Unity通用泛型单例设计模式(普通型和继承自MonoBehaviour)
网友评论