📄 serial.h
字号:
/*************************************************************************** serial.h - description ------------------- begin : Thu Nov 8 2001 copyright : (C) 2001 by email : ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#ifndef SERIAL_H#define SERIAL_H#include "msystem.h"#include "channelmgr.h"//#include "Device.h"//#include <iosfwd>/** *@author */namespace Serial {enum BaudRateEnum { BAUD_50 = B50, //!< 50 baud. BAUD_75 = B75, //!< 75 baud. BAUD_110 = B110, //!< 110 baud. BAUD_134 = B134, //!< 134.5 baud. Yes 134.5. I did not mistype that. BAUD_150 = B150, //!< 150 baud. BAUD_200 = B200, //!< 200 baud. BAUD_300 = B300, //!< 300 baud. BAUD_600 = B600, //!< 600 baud. BAUD_1200 = B1200, //!< 1200 baud. BAUD_1800 = B1800, //!< 1800 baud. BAUD_2400 = B2400, //!< 2400 baud. BAUD_4800 = B4800, //!< 4800 baud. BAUD_9600 = B9600, //!< 9600 baud. BAUD_19200 = B19200, //!< 19200 baud. BAUD_38400 = B38400, //!< 38400 baud. BAUD_INVALID //!< Invalid baud rate.} ; /** The allowed values of character sizes that can be used during the serial communication. */enum CharSizeEnum { CHAR_SIZE_5 = CS5, //!< 5 bit characters. CHAR_SIZE_6 = CS6, //!< 6 bit characters. CHAR_SIZE_7 = CS7, //!< 7 bit characters. CHAR_SIZE_8 = CS8, //!< 8 bit characters. CHAR_SIZE_INVALID //!< Invalid character size.} ; /** The allowed values of the parity associated with the serial port communications. */enum ParityEnum { PARITY_EVEN, //!< Even parity. PARITY_ODD, //!< Odd parity. PARITY_NONE, //!< No parity i.e. parity checking disabled. PARITY_INVALID //!< Invalid parity value.} ; /** The values of the flow control settings for a serial port. */enum FlowControlEnum { FLOW_CONTROL_HARD, //!< Hardware flow control. FLOW_CONTROL_SOFT, //!< Software flow control. FLOW_CONTROL_INVALID //!< Invalid flow control setting.} ;class CSerial {public: CSerial(CSerialPortDef *pChannel) { m_pChannel = pChannel; m_hFile = -1; } ~CSerial() { if (IsOpen()) Close(); m_hFile = -1; } bool Open(); int GetFileHandle() {return m_hFile;} void Close();protected: int m_hFile; bool IsOpen() const { return (-1 != m_hFile) ; } const BaudRateEnum SetBaudRate(const BaudRateEnum baud_rate) ; const BaudRateEnum BaudRate() const ; const CharSizeEnum CharSize() const ; const CharSizeEnum SetCharSize(const CharSizeEnum char_size) ; short SetNumOfStopBits(short stop_bits) ; short NumOfStopBits() const ; const ParityEnum SetParity(const ParityEnum parity) ; const ParityEnum Parity() const ; const FlowControlEnum SetFlowControl(const FlowControlEnum flow_c) ; const FlowControlEnum FlowControl() const ; CSerialPortDef* m_pChannel; bool InitializeSerialPort(); bool SetParameters(); //Character used to signal that I/O can start while using software flow control with the serial port. static const char CTRL_Q = 0x11 ; //Character used to signal that I/O should stop while using software flow control with the serial port. static const char CTRL_S = 0x13 ;};//end class}; //end namespace#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -