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 |
|
#endif |
15 |
|
|
16 |
|
|
17 |
class CSerial |
class CSerial |
18 |
{ |
{ |
19 |
|
#ifdef _WINDOWS |
20 |
HANDLE mComport; |
HANDLE mComport; |
21 |
DCB mDcbRestore; |
DCB mDcbRestore; |
22 |
CString mPortstr; |
#else |
23 |
|
int mFiledescriptor; |
24 |
|
#endif |
25 |
|
|
26 |
|
char* mPortstr; |
27 |
int mBitrate; |
int mBitrate; |
28 |
bool mIsopen; |
bool mIsopen; |
29 |
|
|
30 |
protected: |
//void printByte(char* description, unsigned char byte); |
|
void printByte(char* description, unsigned char byte); |
|
31 |
public: |
public: |
32 |
CSerial(); |
CSerial(); |
33 |
CSerial(char* port, int bitrate); |
CSerial(char* port, int bitrate); |
39 |
unsigned char readByte(); |
unsigned char readByte(); |
40 |
void writeByte(unsigned char out); |
void writeByte(unsigned char out); |
41 |
|
|
42 |
|
#ifdef _WINDOWS |
43 |
COMSTAT getComstat() const; |
COMSTAT getComstat() const; |
44 |
|
#endif |
45 |
int bytesReady() const; |
int bytesReady() const; |
46 |
int outQueueSize() const; |
int outQueueSize() const; |
47 |
CString getPort() const {return mPortstr;} |
char* getPort() const {return mPortstr;} |
48 |
int getBitrate() const {return mBitrate;} |
int getBitrate() const {return mBitrate;} |
49 |
|
|
50 |
bool isOpen() { return mIsopen; } |
bool isOpen() { return mIsopen; } |
52 |
//void writeBytes(UCVector out); |
//void writeBytes(UCVector out); |
53 |
//UCVector readBytes(int maxcount); |
//UCVector readBytes(int maxcount); |
54 |
protected: |
protected: |
55 |
void open(); |
|
56 |
|
#ifdef _WINDOWS |
57 |
|
void openWindows(); |
58 |
|
#else |
59 |
|
void openLinux(); |
60 |
|
#endif |
61 |
}; |
}; |