⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serialport.h

📁 用一个开源码ASCII ENCODE,DECODE,来发送ASCII短信
💻 H
字号:
#ifndef __SerialPort_included	#define __SerialPort_included#endif#ifndef __termios_included	#define __termios_included	#include <termios.h> /* POSIX terminal control definitions */#endif#ifndef __fcntl_included	#define __fcntl_included	#include <fcntl.h>	/* File control definitions */#endif#ifndef __stdio_included	#define __stdio_included	#include <stdio.h>	/* Standard input/output definitions */#endif#ifndef __unistd_included	#define __unistd_included	#include <unistd.h>	/* UNIX standard function definitions */#endif// Referenced from http://www.easysw.com/~mike/serial/serial.htmlnamespace SerialPorts {		enum BaudRateEnum {        BAUD_50    = B50,        BAUD_75    = B75,        BAUD_110   = B110,        BAUD_134   = B134,        BAUD_150   = B150,        BAUD_200   = B200,        BAUD_300   = B300,        BAUD_600   = B600,        BAUD_1200  = B1200,        BAUD_1800  = B1800,        BAUD_2400  = B2400,        BAUD_4800  = B4800,        BAUD_9600  = B9600,        BAUD_19200 = B19200,        BAUD_38400 = B38400,        BAUD_57600 = B57600,        BAUD_115200 = B115200,        BAUD_ERR,	};		enum CharSizeEnum {        CHAR_SIZE_5 = CS5,        CHAR_SIZE_6 = CS6,        CHAR_SIZE_7 = CS7,        CHAR_SIZE_8 = CS8,        CHAR_SIZE_ERR    };	enum ParityEnum {        PARITY_EVEN,        PARITY_ODD,        PARITY_NONE,        PARITY_ERR    };        	enum FlowControlEnum {        FLOW_CONTROL_HARD,        FLOW_CONTROL_SOFT,        FLOW_CONTROL_NONE,        FLOW_CONTROL_ERR    };        const BaudRateEnum DEFAULT_BAUDRATE = BAUD_9600;    const CharSizeEnum DEFAULT_CHARSIZE = CHAR_SIZE_8;    const ParityEnum DEFAULT_PARITY = PARITY_NONE;    const FlowControlEnum DEFAULT_FLOWCONTROL = FLOW_CONTROL_NONE;    	static const char CTRL_Q = 0x11 ;	static const char CTRL_S = 0x13 ;            class SerialPort {    	private:    		int fd;    		int state;    		int stopbits;    		enum BaudRateEnum baud;    		enum CharSizeEnum charsize;    		enum ParityEnum parity;    		enum FlowControlEnum flowctrl;    		    	public:    		SerialPort(){				this->state = -1; this->fd = -1;			}    		~SerialPort(){};    		int open(char * devicename);    		int close();    		int status();    		int write( char * data, int lenght);    		char readChar();    		char * readBytes(int bytes);    		int dataWaiting();    		    		enum BaudRateEnum setBaudRate( enum BaudRateEnum bps);    		//enum BaudRateEnum getBaudRate();    		    		enum CharSizeEnum setCharSize( enum CharSizeEnum charsize);    		enum ParityEnum setParity( enum ParityEnum parity);    		int setStopBits(int stopbits);    		enum FlowControlEnum setFlowControl( enum FlowControlEnum flowctrl);    		  		    }; //class SerialPort}; //namespace SerialPorts

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -