Subversion Repositories Programming Utils

Rev

Rev 81 | Rev 96 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
95 rm5248 1
package com.rm5248.serial;
2
 
3
import java.io.IOException;
4
 
5
/**
6
 * A SerialPort represents a serial port on the system.
7
 *
8
 * All SerialPorts must implement this class.
9
 *
10
 * See the documentation for the subclasses on how to create
11
 * a specific instance of a SerialPort.
12
 *
13
 * @author rm5248
14
 *
15
 */
16
public interface SerialPort {
17
 
18
        /**
19
         * Represents the BaudRate that the SerialPort uses.
20
         */
21
        public enum BaudRate{
22
                /** Not available in Windows */
23
                B0,
24
                /** Not available in Windows */
25
                B50,
26
                /** Not available in Windows */
27
                B75,
28
                B110,
29
                /** Not available in Windows */
30
                B134,
31
                /** Not available in Windows */
32
                B150,
33
                B200,
34
                B300,
35
                B600,
36
                B1200,
37
                /** Not available in Windows */
38
                B1800,
39
                B2400,
40
                B4800,
41
                B9600,
42
                B38400,
43
                B115200
44
        }
45
 
46
        /**
47
         * Represents the number of bits that the serial port uses.  
48
         * Typically, this is 8-bit characters.
49
         */
50
        public enum DataBits{
51
                DATABITS_5,
52
                DATABITS_6,
53
                DATABITS_7,
54
                DATABITS_8
55
        }
56
 
57
        /**
58
         * The number of stop bits for data.  Typically this is 1.
59
         */
60
        public enum StopBits{
61
                STOPBITS_1,
62
                STOPBITS_2
63
        }
64
 
65
        /**
66
         * The parity bit for the data.  Typically None.
67
         */
68
        public enum Parity{
69
                NONE,
70
                EVEN,
71
                ODD
72
        }
73
 
74
        /**
75
         * The Flow control scheme for the data, typically None.
76
         */
77
        public enum FlowControl{
78
                NONE,
79
                HARDWARE,
80
                SOFTWARE
81
        }
82
 
83
        /**
84
         * Set the Baud Rate for this port.
85
         *
86
         * @param rate
87
         */
88
        public abstract void setBaudRate(BaudRate rate);
89
 
90
        /**
91
         * Close the serial port, and all input streams
92
         */
93
        public abstract void close();
94
 
95
        /**
96
         * See if the port has been closed already.
97
         * @return
98
         */
99
        public abstract boolean isClosed();
100
 
101
        /**
102
         * Set the stop bits of the serial port, after the port has been opened.
103
         *
104
         * @param stop
105
         */
106
        public abstract void setStopBits(StopBits stop);
107
 
108
        /**
109
         * Set the data bits size, after the port has been opened.
110
         *
111
         * @param data
112
         */
113
        public abstract void setDataSize(DataBits data);
114
 
115
        /**
116
         * Set the parity of the serial port, after the port has been opened.
117
         *
118
         * @param parity
119
         */
120
        public abstract void setParity(Parity parity);
121
 
122
        /**
123
         * Get the serial line state for the specified serial port.
124
         *
125
         * @return
126
         */
127
        public abstract SerialLineState getSerialLineState() throws IOException;
128
 
129
        /**
130
         * Set the serial line state to the parameters given.
131
         *
132
         * @param state
133
         */
134
        public abstract void setSerialLineState(SerialLineState state);
135
 
136
        /**
137
         * Get the baud rate of the serial port.
138
         *
139
         * @return
140
         */
141
        public abstract IOSerialPort.BaudRate getBaudRate();
142
 
143
        /**
144
         * Get the number of data bits.
145
         *
146
         * @return
147
         */
148
        public abstract IOSerialPort.DataBits getDataBits();
149
 
150
        /**
151
         * Get the number of stop bits.
152
         *
153
         * @return
154
         */
155
        public abstract IOSerialPort.StopBits getStopBits();
156
 
157
        /**
158
         * Get the parity of the serial port.
159
         *
160
         * @return
161
         */
162
        public abstract IOSerialPort.Parity getParity();
163
 
164
        /**
165
         * Get the flow control for the serial port.
166
         *
167
         * @return
168
         */
169
        public abstract IOSerialPort.FlowControl getFlowControl();
170
 
171
        /**
172
         * Set the flow control for the serial port
173
         *
174
         * @param flow
175
         */
176
        public abstract void setFlowControl(FlowControl flow);
177
 
178
        /**
179
         * Set the listener which will get events when there is activity on the serial port.
180
         * Note that this activity does NOT include receive and transmit events - this is
181
         * changes on the lines of the serial port, such as RI, DSR, and DTR.
182
         *
183
         * If listen is null, will remove the listener.
184
         *
185
         * @param listen The listener which gets events
186
         */
187
        public abstract void setSerialChangeListener(SerialChangeListener listen);
188
 
189
        /**
190
         * Get the name of the serial port that this object represents.
191
         * @return
192
         */
193
        public abstract String getPortName();
194
 
195
}