C#实现把指定数据写入串口
publicstaticboolWriteToSerialPort(byte[]byteArr)
{
SerialPortCom=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);
returntrue;
}
catch(Exceptionex)
{
returnfalse;
}
finally
{
Com.Close();
}
}
本例使用的是方法Write(Byte[]buffer,Int32offset,Int32count)。该方法使用缓冲区的数据将指定数量的字节写入串行端口。buffer为缓冲区,offset表示从此处开始将字节复制到端口,count表示要写入的字节数。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短