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