/[H7]/branches/linux-serial/Serial.h
ViewVC logotype

Contents of /branches/linux-serial/Serial.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (show annotations) (download)
Sun Feb 4 23:11:02 2007 UTC (17 years, 3 months ago) by torben
File MIME type: text/plain
File size: 1158 byte(s)
First take at making this linux-serial-thingie work...


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

  ViewVC Help
Powered by ViewVC 1.1.20