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