1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 SERSTRM.H                                 */
4 /*                                                                           */
5 /* (C) 1996     Ullrich von Bassewitz                                        */
6 /*              Wacholderweg 14                                              */
7 /*              D-70597 Stuttgart                                            */
8 /* EMail:       uz@musoftware.com                                            */
9 /*                                                                           */
10 /*****************************************************************************/
11 
12 
13 
14 // $Id$
15 //
16 // $Log$
17 //
18 //
19 
20 
21 
22 // A serial character stream using the sercom module.
23 
24 
25 
26 #ifndef _SERSTRM_H
27 #define _SERSTRM_H
28 
29 
30 
31 #include "sercom.h"
32 #include "charstrm.h"
33 
34 
35 
36 /*****************************************************************************/
37 /*                            class SerialStream                             */
38 /*****************************************************************************/
39 
40 
41 
42 class SerialStream: public CharacterStream {
43 
44 protected:
45     ComPort     Port;
46 
47 public:
48     SerialStream (const String& aPortName,
49                   u32  aBaudrate    = 9600,
50                   char aDatabits    =    8,  // 5..8
51                   char aParity      =  'N',  // <N>one, <O>dd, <E>ven, <M>ark, <S>pace
52                   char aStopbits    =    1,  // 1, 2
53                   char aConnection  =  'M',  // <D>irect, <M>odem
54                   char aXonXoff     =  'D',  // <E>nabled, <D>isabled
55                   unsigned UARTBase = 0,     // I/O base address, DOS only
56                   unsigned IntNum   = 0      // Number of interrupt used, DOS only
57                  );
58     // Create a SerialStream object, use defaults for timeouts and buffer sizes
59 
60     virtual ~SerialStream ();
61     // Close the port
62 
63     void SetBufferSize (unsigned aRXBufSize, unsigned aTXBufSize);
64     // Set the sizes for receive and transmit buffer. This function cannot
65     // be called if the port is already open, you have to call it after
66     // constructing the object or after a close. The function may be ignored
67     // if it is not possible to change buffer sizes.
68 
69     virtual void SetReadTimeout (double T);
70     // Set the read timeout for the stream.
71     // A value of zero means no timeout (error if data not immidiately
72     // available) a value less than zero means "indefinite wait".
73     // Beware: The implementation of the timeout is device dependent! As an
74     // example, there may be devices that cannot do timeouts less than one
75     // second.
76 
77     virtual void SetWriteTimeout (double T);
78     // Set the write timeout for the stream.
79     // A value of zero means no timeout (error if data cannot be written
80     // immidiately) a value less than zero means "indefinite wait".
81     // Beware: The implementation of the timeouts is device dependent! As an
82     // example, there may be devices that cannot do timeouts less than one
83     // second.
84 
85     virtual size_t ReadCount () const;
86     // Return the amount of bytes that can be read without waiting. On many
87     // devices it is impossible to tell the exact number, in these cases the
88     // function returns a value of 1 if at least one byte can be read without
89     // blocking and 0 otherwise.
90 
91     virtual size_t WriteCount () const;
92     // Return the amount of bytes that can be written without waiting. On many
93     // devices it is impossible to tell the exact number, in these cases the
94     // function returns a value of 1 if at least one byte can be written without
95     // blocking and 0 otherwise.
96 
97     virtual void Read (void* Buf, size_t Count);
98     // Read from the stream
99 
100     virtual void Write (const void* Buf, size_t Count);
101     // Write to the stream
102 
103 };
104 
105 
106 
107 // End of SERSTRM.H
108 
109 #endif
110 
111 
112 
113