1 |
/*
|
2 |
* Serial.h & Serial.cpp - (C) 2007 by Torben H. Nielsen
|
3 |
*
|
4 |
* A wrapper class for communicating with a serial port
|
5 |
*/
|
6 |
|
7 |
#pragma once
|
8 |
|
9 |
#include <vector>
|
10 |
|
11 |
typedef std::vector<unsigned char> UCVector;
|
12 |
|
13 |
class CSerial
|
14 |
{
|
15 |
HANDLE mComport;
|
16 |
DCB mDcbRestore;
|
17 |
CString mPortstr;
|
18 |
int mBitrate;
|
19 |
bool mIsopen;
|
20 |
|
21 |
protected:
|
22 |
void printByte(char* description, unsigned char byte);
|
23 |
public:
|
24 |
CSerial();
|
25 |
CSerial(char* port, int bitrate);
|
26 |
~CSerial(void);
|
27 |
|
28 |
void close();
|
29 |
void open(char* port, int bitrate);
|
30 |
|
31 |
unsigned char readByte();
|
32 |
void writeByte(unsigned char out);
|
33 |
|
34 |
|
35 |
COMSTAT getComstat() const;
|
36 |
int bytesReady() const;
|
37 |
int outQueueSize() const;
|
38 |
CString getPort() const {return mPortstr;}
|
39 |
int getBitrate() const {return mBitrate;}
|
40 |
|
41 |
bool isOpen() { return mIsopen; }
|
42 |
|
43 |
//void writeBytes(UCVector out);
|
44 |
//UCVector readBytes(int maxcount);
|
45 |
protected:
|
46 |
void open();
|
47 |
};
|