Subversion Repositories Programming Utils

Rev

Rev 38 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9 rm5248 1
package com.rm5248.serial;
2
 
3
import java.io.IOException;
4
import java.io.InputStream;
5
 
6
/**
95 rm5248 7
 * Input stream for the serial port.  This implementation passes back the
8
 * status of the control lines in the upper bits of {@code read()}, and
9
 * thus must be parsed properly.
9 rm5248 10
 */
11
class SerialInputStream extends InputStream{
12
        /* The handle to read from.  Needed for native implementation */
13
        @SuppressWarnings("unused")
14
        private int handle;
38 rm5248 15
 
9 rm5248 16
 
17
        SerialInputStream( int handle ){
18
                this.handle = handle;
19
        }
20
 
21
        @Override
22
        public int read() throws IOException{
23
                return readByte();
24
        }
25
 
26
        @Override
27
        public int available() throws IOException{
28
                return getAvailable();
29
        }
30
 
31
        private native int readByte() throws IOException;
32
 
33
        private native int getAvailable() throws IOException;
95 rm5248 34
}
35
 
36
/**
37
 * A SimpleSerialInputStream does not pass back the status of the control
38
 * lines on the serial port - just the raw bytes.
39
 */
40
class SimpleSerialInputStream extends InputStream {
41
        /* The handle to read from.  Needed for native implementation */
42
        @SuppressWarnings("unused")
43
        private int handle;
44
 
45
 
46
        SimpleSerialInputStream( int handle ){
47
                this.handle = handle;
48
        }
49
 
50
        @Override
51
        public int read() throws IOException{
52
                return readByte();
53
        }
54
 
55
        @Override
56
        public int available() throws IOException{
57
                return getAvailable();
58
        }
59
 
60
        private native int readByte() throws IOException;
61
 
62
        private native int getAvailable() throws IOException;
9 rm5248 63
}