📄 serial.h
字号:
////////////////////////////////////
// Base class for SERIAL_COMMUNICATION, nonoverlapped
//
// File : serial.h
//
// Author : L. Saint-Marcel
// lstmarcel@yahoo.fr
//
// Date : 06/31/01
////////////////////////////////////
#ifndef __SERIAL_H_LSM__
#define __SERIAL_H_LSM__
#include <windows.h>
#include <commctrl.h>
#define DEFAULT_READ_TIMEOUT 500 // milliseconds
#ifdef SERIAL_ERROR
#undef SERIAL_ERROR
#endif
#ifdef SERIAL_SUCCESS
#undef SERIAL_SUCCESS
#endif
#define SERIAL_ERROR -1
#define SERIAL_SUCCESS 0
#define DEFAULT_PORT_NAME "COM1"
class serialCL{
public :
serialCL();
~serialCL();
int open(char* gszPort = DEFAULT_PORT_NAME,
long speed = 9600,
int parity = NOPARITY,
int bitslength = 8,
int stopbit = ONESTOPBIT);
int close();
// send a request to read length bytes, do not wait for them...
int read(unsigned char * buffer,
unsigned long & length);
// read length Bytes (wait for them), return only when read =length or read error
int forceRead(unsigned char * lpBuf,
unsigned long &length);
int write(unsigned char * buffer,
unsigned long length);
private :
char gszPort_[256];
HANDLE CommPortHandle; //Holds the handle to the communications port returned by windows.
COMMTIMEOUTS CommPortTimeOut; // This data structure is programmed with timeout parameters for the serial port
DCB CommPortDCB; // This data structure is programmed with the serial port parameters.
short PortInitSuccessful; // This data member is assigned 1 if the serial port is successfully initialized, otherwise it is 0.
unsigned long BytesTransferred; // Holds the number of bytes transferred during a serial port read or write operation. This is here just as a placeholder for windows API functions.
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -