~ubuntu-branches/ubuntu/precise/primrose/precise

« back to all changes in this revision

Viewing changes to minorGems/io/serialPort/SerialPort.h

  • Committer: Bazaar Package Importer
  • Author(s): Paul Wise
  • Date: 2009-04-06 19:26:56 UTC
  • Revision ID: james.westby@ubuntu.com-20090406192656-cri7503gebyvfl8t
Tags: upstream-5+dfsg1
ImportĀ upstreamĀ versionĀ 5+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Modification History
 
3
 *
 
4
 * 2003-February-17   Jason Rohrer
 
5
 * Created.
 
6
 *
 
7
 * 2003-April-4   Jason Rohrer
 
8
 * Added function for dumping the read buffer.
 
9
 */
 
10
 
 
11
 
 
12
 
 
13
#ifndef SERIAL_PORT_INCLUDED
 
14
#define SERIAL_PORT_INCLUDED
 
15
 
 
16
 
 
17
 
 
18
/**
 
19
 * Serial port.
 
20
 *
 
21
 * Note:  Implementation for the functions defined here is provided
 
22
 *   separately for each platform (in the mac/ linux/ and win32/ 
 
23
 *   subdirectories).
 
24
 *
 
25
 * @author Jason Rohrer
 
26
 */ 
 
27
class SerialPort {
 
28
 
 
29
 
 
30
        
 
31
    public:
 
32
 
 
33
 
 
34
        
 
35
        static const int PARITY_NONE  = 0;
 
36
        static const int PARITY_EVEN  = 1;
 
37
        static const int PARITY_ODD   = 2;
 
38
        
 
39
 
 
40
 
 
41
        /**
 
42
         * Constructs a serial port.
 
43
         *
 
44
         * @param inBaud the baud rate.
 
45
         * @param inParity the parity, one of SerialPort:: PARITY_NONE,
 
46
         *   PARITY_EVEN, or PARITY_ODD.
 
47
         * @param inDataBits the number of data bits, 5, 6, 7, or 8.
 
48
         * @param inStopBits the number of stop bits, 1 or 2.
 
49
         */
 
50
        SerialPort( int inBaud, int inParity, int inDataBits, int inStopBits );
 
51
 
 
52
 
 
53
        
 
54
        ~SerialPort();
 
55
 
 
56
 
 
57
 
 
58
        /**
 
59
         * Sends a line of text through this serial port.
 
60
         *
 
61
         * @param inLine the \0-terminated line of text to send.
 
62
         *   Should not contain newline characters.
 
63
         *   Must be destroyed by caller if non-const.
 
64
         *
 
65
         * @return 1 if the line was sent successfully,
 
66
         *   or -1 for a port error.
 
67
         */
 
68
        int sendLine( char *inLine );
 
69
 
 
70
        
 
71
        
 
72
        /**
 
73
         * Receives a line of text from this serial port.
 
74
         *
 
75
         * @return the read line as a \0-terminated string with end of
 
76
         *   line characters included, or NULL for a port error.
 
77
         *   Must be destroyed by caller if non-NULL.
 
78
         */
 
79
        char *receiveLine();
 
80
 
 
81
 
 
82
 
 
83
        /**
 
84
         * Discards all characters in the receive buffer, including
 
85
         * unread characters.
 
86
         *
 
87
         * Can be used to recover from buffer overflow problems.
 
88
         */
 
89
        void dumpReceiveBuffer();
 
90
 
 
91
        
 
92
 
 
93
    private:
 
94
 
 
95
 
 
96
 
 
97
        /**
 
98
         * Used for platform-specific implementations.
 
99
         */
 
100
        void *mNativeObjectPointer;
 
101
 
 
102
 
 
103
        
 
104
    };
 
105
 
 
106
 
 
107
 
 
108
#endif