标签:
串口进行操作的类,其中包括写和读操作,类可设置串口参数、设置接收函数、打开串口资源、关闭串口资源,操作完成后,一定要关闭串口、接收串口数据事件、接收数据出错事件、获取当前全部串口、把字节型转换成十六进制字符串等功能。这个串口类已经过了调试,可以使用: using System; using System.Collections.Generic; using System.Text; using System.IO.Ports; using System.Globalization; namespace SerialClass { public class SerialClass { SerialPort _serialPort = null; //定义委托 public delegate void SerialPortDataReceiveEventArgs(object sender, SerialDataReceivedEventArgs e, byte[] bits); //定义接收数据事件 public event SerialPortDataReceiveEventArgs DataReceived; //定义接收错误事件 //public event SerialErrorReceivedEventHandler Error; //接收事件是否有效 false表示有效 public bool ReceiveEventFlag = false; #region 获取串口名 private string protName; public string PortName { get { return _serialPort.PortName; } set { _serialPort.PortName = value; protName = value; } } #endregion #region 获取比特率 private int baudRate; public int BaudRate { get { return _serialPort.BaudRate; } set { _serialPort.BaudRate = value; baudRate = value; } } #endregion #region 默认构造函数 ///标签:
原文地址:http://www.cnblogs.com/netlyf/p/4458927.html