9 |
#include <vector> |
#include <vector> |
10 |
#include <string> |
#include <string> |
11 |
#include <stdexcept> |
#include <stdexcept> |
|
typedef std::vector<unsigned char> UCVector; |
|
12 |
|
|
13 |
#ifndef _MSC_VER // |
#ifndef _MSC_VER // |
14 |
inline void Sleep(int x) { usleep(x*1000);} |
inline void Sleep(int x) { usleep(x*1000);} |
33 |
Baud57600, |
Baud57600, |
34 |
Baud115200 |
Baud115200 |
35 |
}; |
}; |
|
private: // member vars |
|
|
#ifdef _MSC_VER |
|
|
HANDLE mComport; |
|
|
DCB mDcbRestore; |
|
|
#else |
|
|
int mFiledescriptor; |
|
|
termios mOldtio; |
|
|
#endif |
|
|
|
|
|
char* mPortstr; |
|
|
Baudrate mBitrate; |
|
|
bool mIsopen; |
|
36 |
|
|
37 |
public: //public methods |
public: //public methods |
38 |
CSerial(); |
CSerial(); |
45 |
int readByte(); |
int readByte(); |
46 |
void writeByte(unsigned char out); |
void writeByte(unsigned char out); |
47 |
|
|
48 |
|
void writeBytes(unsigned char* buf, unsigned int len); |
49 |
|
int readBytes(unsigned char* buf, unsigned int maxLen); |
50 |
|
|
51 |
#ifdef _MSC_VER |
#ifdef _MSC_VER |
52 |
COMSTAT getComstat() const; |
COMSTAT getComstat() const; |
53 |
#endif |
#endif |
58 |
|
|
59 |
bool isOpen() { return mIsopen; } |
bool isOpen() { return mIsopen; } |
60 |
|
|
|
//void writeBytes(UCVector out); |
|
|
//UCVector readBytes(int maxcount); |
|
61 |
protected: |
protected: |
62 |
|
|
63 |
void printByte(char* description, unsigned char byte); |
void printByte(char* description, unsigned char byte); |
64 |
int convertBaudrate(Baudrate rate); |
int convertBaudrate(Baudrate rate); |
65 |
|
|
66 |
#ifdef _MSC_VER |
#ifdef _MSC_VER |
67 |
void openWindows(); |
void openWindows(); |
68 |
|
int readBytesWindows(unsigned char*buf, unsigned int maxLen); |
69 |
|
void writeBytesWindows(unsigned char* buf, unsigned int len); |
70 |
#else |
#else |
71 |
void openLinux(); |
void openLinux(); |
72 |
|
int readBytesLinux(unsigned char* buf, unsigned int maxLen); |
73 |
|
void writeBytesLinux(unsigned char* buf, unsigned int len); |
74 |
#endif |
#endif |
75 |
|
|
76 |
|
|
77 |
|
private: // member vars |
78 |
|
#ifdef _MSC_VER |
79 |
|
HANDLE mComport; |
80 |
|
DCB mDcbRestore; |
81 |
|
#else |
82 |
|
int mFiledescriptor; |
83 |
|
termios mOldtio; |
84 |
|
#endif |
85 |
|
|
86 |
|
char* mPortstr; |
87 |
|
Baudrate mBitrate; |
88 |
|
bool mIsopen; |
89 |
}; |
}; |