文档详情

serialClass(国外英文资料).doc

发布:2017-06-06约1.21万字共29页下载文档
文本预览下载声明
serialClass(国外英文资料) Manipulation, serial ports, including read and write operation, the class can be set up a serial port parameters, sets the receive function, open the serial port, close a serial port resources, after the completion of the operation, be sure to close a serial port, receive serial data, receive data error events, for current all serial ports, the byte type convert hexadecimal string, etc. This serial class has been debugged and can be used: The view sourceprint? 001 using System; 002 using System. Collections. Generic; 003 using System. The Text; 004 using System. IO. Ports; 005 using System. Globalization; 006 the namespace SerialClass 007 { 008 public class SerialClass 009 { 010 SerialPort _serialPort = null; 011 / / define the delegate 012 public delegate void SerialPortDataReceiveEventArgs (object sender, SerialDataReceivedEventArgs e, byte [] bits); 013 / / define receive data events 014 public event serialportdatargs DataReceived; 015 / / define receive error events 016 / / public event SerialErrorReceivedEventHandler Error; The 017 / / receive event is valid for false 018 public bool ReceiveEventFlag = false; 019 # region gets the serial name 020 private string protName; 021 public string PortName 022 { 023 get {return _serialPort. } 024 set 025 { 026 _serialPort. PortName = value; The protName = value; 028} 029} 030 # endregion 031 # region gets bitrates 032 private int baudRate; 033 public int BaudRate 034 { 035 get {return _serialPort. } Set of 036 037 { 038 _serialport.baudrate = value. 039 baudRate = value; 040} 041} 042 # endregion The default constructor for region 043 044 / / summary 045 / / / the default constructor, operating COM1, the rate of 9600, no Parity, 8 bytes, COM1 stop bit is 1, 9600, Parity. None, 8, StopBits. One 046 / / summary 047 public SerialClass () 048 { 049 _serialPort = new SerialPort (); 050} 051 # endregion 052 # region constructors 053 / / summary 054 / / constructor, 055 / / / summary 056 / / param
显示全部
相似文档