blob: cff2e3732dc93b92796d1a966fb7b6286457f110 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package org.reprap.comms.port;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.comm.CommPortIdentifier;
import javax.comm.NoSuchPortException;
public class SerialPort implements Port {
private javax.comm.SerialPort port;
public SerialPort(String portName, int baudRate) throws Exception {
try {
CommPortIdentifier commId = CommPortIdentifier.getPortIdentifier(portName);
port = (javax.comm.SerialPort)commId.open(portName, 30000);
}
catch (NoSuchPortException ex) {
}
// Workround for javax.comm bug.
// See http://forum.java.sun.com/thread.jspa?threadID=673793
try {
port.setSerialPortParams(baudRate,
javax.comm.SerialPort.DATABITS_8,
javax.comm.SerialPort.STOPBITS_1,
javax.comm.SerialPort.PARITY_NONE);
}
catch (Exception e) {
port.setSerialPortParams(baudRate,
javax.comm.SerialPort.DATABITS_8,
javax.comm.SerialPort.STOPBITS_1,
javax.comm.SerialPort.PARITY_NONE);
}
// End of workround
try {
port.setFlowControlMode(javax.comm.SerialPort.FLOWCONTROL_NONE);
} catch (Exception e) {
// Um, Linux USB ports don't do this. What can I do about it?
}
}
public OutputStream getOutputStream() throws IOException {
return port.getOutputStream();
}
public InputStream getInputStream() throws IOException {
return port.getInputStream();
}
public void close() {
port.close();
}
}
|