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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (hide 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 torben 38 /*
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 torben 44 #ifndef _WINDOWS //
13     inline void Sleep(int x) { usleep(x*1000);}
14 torben 46 #include <termios.h>
15 torben 44 #endif
16    
17    
18 torben 38 class CSerial
19     {
20 torben 44 #ifdef _WINDOWS
21 torben 38 HANDLE mComport;
22     DCB mDcbRestore;
23 torben 44 #else
24     int mFiledescriptor;
25 torben 46 termios mOldtio;
26 torben 44 #endif
27    
28     char* mPortstr;
29 torben 38 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 torben 44 #ifdef _WINDOWS
44 torben 38 COMSTAT getComstat() const;
45 torben 44 #endif
46 torben 38 int bytesReady() const;
47     int outQueueSize() const;
48 torben 44 char* getPort() const {return mPortstr;}
49 torben 38 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 torben 44
57 torben 46 void printByte(char* description, unsigned char byte);
58 torben 44 #ifdef _WINDOWS
59     void openWindows();
60     #else
61     void openLinux();
62     #endif
63 torben 38 };

  ViewVC Help
Powered by ViewVC 1.1.20