Cross plantform versiongit status !

This commit is contained in:
xinyang
2019-05-14 22:22:33 +08:00
parent 601bf2a510
commit f9eab62680
30 changed files with 13231 additions and 392 deletions

View File

@@ -0,0 +1,61 @@
#ifndef _SERIAL_H_
#define _SERIAL_H_
#ifdef Windows
#include <Windows.h>
class Serial
{
public:
Serial(UINT baud = CBR_115200, char parity = 'N', UINT databits = 8, UINT stopsbits = 1, DWORD dwCommEvents = EV_RXCHAR);
~Serial();
bool InitPort(UINT portNo = 1, UINT baud = CBR_9600, char parity = 'N', UINT databits = 8, UINT stopsbits = 1, DWORD dwCommEvents = EV_RXCHAR);
UINT GetBytesInCOM() const ;
bool WriteData(const unsigned char* pData, unsigned int length);
bool ReadData(unsigned char* buffer, unsigned int length);
private:
bool openPort(UINT portNo);
void ClosePort();
void ErrorHandler();
private:
HANDLE hComm;
UINT portNo;
UINT baud;
char parity;
UINT databits;
UINT stopsbits;
DWORD dwCommEvents;
};
#elif defined(Linux)
#include <errno.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
class Serial {
private:
int fd;
int nSpeed;
char nEvent;
int nBits;
int nStop;
int set_opt(int fd, int nSpeed, char nEvent, int nBits, int nStop);
public:
Serial(int nSpeed = 115200, char nEvent = 'N', int nBits = 8, int nStop = 1);
~Serial();
bool InitPort(int nSpeed = 115200, char nEvent = 'N', int nBits = 8, int nStop = 1);
// int GetBytesInCOM() const ;
bool WriteData(const unsigned char* pData, unsigned int length);
bool ReadData(unsigned char* buffer, unsigned int length);
};
#endif
#endif /* _SERIAL_H_ */