7 |
#pragma once |
#pragma once |
8 |
|
|
9 |
#include <vector> |
#include <vector> |
10 |
|
#include <string> |
11 |
|
#include <stdexcept> |
12 |
typedef std::vector<unsigned char> UCVector; |
typedef std::vector<unsigned char> UCVector; |
13 |
|
|
14 |
|
#ifndef _WINDOWS // |
15 |
|
inline void Sleep(int x) { usleep(x*1000);} |
16 |
|
#include <termios.h> |
17 |
|
#endif |
18 |
|
|
19 |
|
|
20 |
class CSerial |
class CSerial |
21 |
{ |
{ |
22 |
|
#ifdef _WINDOWS |
23 |
HANDLE mComport; |
HANDLE mComport; |
24 |
DCB mDcbRestore; |
DCB mDcbRestore; |
25 |
CString mPortstr; |
#else |
26 |
|
int mFiledescriptor; |
27 |
|
termios mOldtio; |
28 |
|
#endif |
29 |
|
|
30 |
|
char* mPortstr; |
31 |
int mBitrate; |
int mBitrate; |
32 |
bool mIsopen; |
bool mIsopen; |
33 |
|
|
|
protected: |
|
|
void printByte(char* description, unsigned char byte); |
|
34 |
public: |
public: |
35 |
CSerial(); |
CSerial(); |
36 |
CSerial(char* port, int bitrate); |
CSerial(char* port, int bitrate); |
39 |
void close(); |
void close(); |
40 |
void open(char* port, int bitrate); |
void open(char* port, int bitrate); |
41 |
|
|
42 |
unsigned char readByte(); |
int readByte(); |
43 |
void writeByte(unsigned char out); |
void writeByte(unsigned char out); |
44 |
|
|
45 |
|
#ifdef _WINDOWS |
46 |
COMSTAT getComstat() const; |
COMSTAT getComstat() const; |
47 |
|
#endif |
48 |
int bytesReady() const; |
int bytesReady() const; |
49 |
int outQueueSize() const; |
int outQueueSize() const; |
50 |
CString getPort() const {return mPortstr;} |
char* getPort() const {return mPortstr;} |
51 |
int getBitrate() const {return mBitrate;} |
int getBitrate() const {return mBitrate;} |
52 |
|
|
53 |
bool isOpen() { return mIsopen; } |
bool isOpen() { return mIsopen; } |
55 |
//void writeBytes(UCVector out); |
//void writeBytes(UCVector out); |
56 |
//UCVector readBytes(int maxcount); |
//UCVector readBytes(int maxcount); |
57 |
protected: |
protected: |
58 |
void open(); |
|
59 |
|
void printByte(char* description, unsigned char byte); |
60 |
|
#ifdef _WINDOWS |
61 |
|
void openWindows(); |
62 |
|
#else |
63 |
|
void openLinux(); |
64 |
|
#endif |
65 |
}; |
}; |