-
Notifications
You must be signed in to change notification settings - Fork 0
/
SerialPort.h
144 lines (105 loc) · 1.86 KB
/
SerialPort.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
///
#ifndef __SERIALPORT__
#define __SERIALPORT__
#include <sys/types.h> // for size_t
#include <stdlib.h> // for NULL
#include <string>
#if WIN32
#include <windows.h>
#else
#include <termios.h>
#endif
///
class SerialPort
{
public:
#if WIN32
///
typedef DWORD Speed;
///
typedef DCB Attributes;
///
typedef HANDLE Port;
#else
///
typedef speed_t Speed;
///
typedef struct termios Attributes;
///
typedef int Port;
#endif // WIN32
///
enum CharSize
{
e0 = 0, // uknown or error
e5 = 5,
e6 = 6,
e7 = 7,
e8 = 8
};
///
enum Parity
{
eNone = 0,
eOdd = 1,
eEven = 2
};
/// constructor
SerialPort(const std::string& thePathName);
/// destructor
~SerialPort();
///
int getIdentifier();
///
bool openPort();
///
void closePort();
///
bool isOpen();
///
size_t isDataAvailable(double theTimeout = 0.0);
///
size_t readData(void* theBuffer, size_t theBufferSize, double theTimeout = 0.0);
///
size_t writeData(const void* theBuffer, size_t theBufferSize);
///
Speed getSpeed();
///
bool setSpeed(Speed theSpeed);
///
CharSize getCharSize();
///
bool setCharSize(CharSize theCharSize);
///
Parity getParity();
///
bool setParity(Parity theParity);
///
bool getDoubleStopBits();
///
bool setDoubleStopBits(bool theDoubleStopBits);
///
bool getSoftwareFlowControl();
///
bool setSoftwareFlowControl(bool theSoftwareFlowControl);
///
bool getHardwareFlowControl();
///
bool setHardwareFlowControl(bool theHardwareFlowControl);
protected:
///
void printData_(const char* theMessage, const void* theBuffer, size_t theBufferSize);
///
bool beginAttrChange_(Attributes& theAttrs);
///
bool endAttrChange_(Attributes& theAttrs);
///
std::string pathName_;
///
Port port_;
///
Attributes oldAttrs_;
///
Attributes newAttrs_;
};
#endif // __SERIALPORT__