Subversion Repositories Projects

Rev

Rev 1532 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1532 Rev 1690
1
package dongfang.mkt.io;
1
package dongfang.mkt.io;
2
 
2
 
3
import gnu.io.CommPort;
3
import gnu.io.CommPort;
4
import gnu.io.CommPortIdentifier;
4
import gnu.io.CommPortIdentifier;
5
import gnu.io.NoSuchPortException;
5
import gnu.io.NoSuchPortException;
6
import gnu.io.SerialPort;
6
import gnu.io.SerialPort;
7
 
7
 
8
import java.io.IOException;
8
import java.io.IOException;
9
import java.io.InputStream;
9
import java.io.InputStream;
10
import java.io.OutputStream;
10
import java.io.OutputStream;
-
 
11
 
11
 
12
/*
12
public class RXTXSerialPort implements MKCommPort {
13
public class RXTXSerialPort implements MKCommPort {
13
        private SerialPort serialPort;
14
        private SerialPort serialPort;
14
 
15
 
15
        public void init(String id) throws IOException {
16
        public void init(String id) throws IOException {
16
                // CommPortIdentifier.getPortIdentifier("COM1");
17
                // CommPortIdentifier.getPortIdentifier("COM1");
17
                // Just take the 1st available port.
18
                // Just take the 1st available port.
18
                CommPortIdentifier portIdentifier = null;
19
                CommPortIdentifier portIdentifier = null;
19
 
20
 
20
                try {
21
                try {
21
                        if (id == null) {
22
                        if (id == null) {
22
                                portIdentifier = (CommPortIdentifier) CommPortIdentifier
23
                                portIdentifier = (CommPortIdentifier) CommPortIdentifier
23
                                                .getPortIdentifiers().nextElement();
24
                                                .getPortIdentifiers().nextElement();
24
                                if (portIdentifier == null) {
25
                                if (portIdentifier == null) {
25
                                        throw new IOException(
26
                                        throw new IOException(
26
                                                        "No serial port found (in search for any serial port).");
27
                                                        "No serial port found (in search for any serial port).");
27
                                }
28
                                }
28
                        } else
29
                        } else
29
                                portIdentifier = CommPortIdentifier.getPortIdentifier(id);
30
                                portIdentifier = CommPortIdentifier.getPortIdentifier(id);
30
                } catch (NoSuchPortException ex) {
31
                } catch (NoSuchPortException ex) {
31
                        throw new IOException(ex.getMessage());
32
                        throw new IOException(ex.getMessage());
32
                }
33
                }
33
 
34
 
34
                System.out.println("Using " + portIdentifier.getName());
35
                System.out.println("Using " + portIdentifier.getName());
35
 
36
 
36
                if (portIdentifier.isCurrentlyOwned()) {
37
                if (portIdentifier.isCurrentlyOwned()) {
37
                        System.out.println("Error: Port is currently in use");
38
                        System.out.println("Error: Port is currently in use");
38
                        return;
39
                        return;
39
                } else {
40
                } else {
40
                        try {
41
                        try {
41
                                CommPort commPort = portIdentifier.open(this.getClass()
42
                                CommPort commPort = portIdentifier.open(this.getClass()
42
                                                .getName(), 2001);
43
                                                .getName(), 2001);
43
                                if (commPort instanceof SerialPort) {
44
                                if (commPort instanceof SerialPort) {
44
                                        serialPort = (SerialPort) commPort;
45
                                        serialPort = (SerialPort) commPort;
45
                                        serialPort.setSerialPortParams(57600,
46
                                        serialPort.setSerialPortParams(57600,
46
                                                        SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
47
                                                        SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
47
                                                        SerialPort.PARITY_NONE);
48
                                                        SerialPort.PARITY_NONE);
48
                                }
49
                                }
49
                        } catch (Exception ex) {
50
                        } catch (Exception ex) {
50
                                throw new IOException(ex.getMessage());
51
                                throw new IOException(ex.getMessage());
51
                        }
52
                        }
52
                }
53
                }
53
        }
54
        }
54
 
55
 
55
        public InputStream getInputStream() throws IOException {
56
        public InputStream getInputStream() throws IOException {
56
                return serialPort.getInputStream();
57
                return serialPort.getInputStream();
57
        }
58
        }
58
 
59
 
59
        public OutputStream getOutputStream() throws IOException {
60
        public OutputStream getOutputStream() throws IOException {
60
                return serialPort.getOutputStream();
61
                return serialPort.getOutputStream();
61
        }
62
        }
62
}
63
}
-
 
64
*/
63
 
65