资源介绍
基于C#串口读写程序
//程序开启,串口初始化
private void Form1_Load(object sender, System.EventArgs e)
{
mycom1.PortNum = iPort;
mycom1.BaudRate = iRate;
mycom1.ByteSize = bSize;
mycom1.Parity = bParity;
mycom1.StopBits = bStopBits;
mycom1.ReadTimeout = iTimeout;
if (this.OpenCom())
msg.AppendText("串口初始化成功……\r\n");
else
msg.AppendText("串口初始化失败!\r\n");
}
//显示包信息
public string dis_package(byte[] reb)
{
string temp = "";
foreach (byte b in reb)
temp += b.ToString("X2") + " ";
return temp;
}
//开串口
public bool OpenCom()
{
try
{
if (mycom1.Opened)
{
mycom1.Close();
mycom1.Open(); //打开串口
- 上一篇: 实现与硬件的串口通讯
- 下一篇: 两种方法实现C#读写文件