3
我想運行這個函數,我得到配置文本gnu.io.rxtx.properties窗口: gnu.io.rxtx.properties尚未檢測到。Java串行端口配置gnu.io.rxtx.properties窗口
在此操作系統上沒有檢測端口的一致手段。在正確的端口枚舉可能發生之前,有必要指出哪些端口在此係統上有效。請檢查在此係統上有效的端口並選擇保存。 當我點擊保存在命令窗口中顯示的文本:
C:\ Program Files文件\的Java \ jre7 \ LIB \ gnu.io.rxtx.SerialPorts
但程序仍然無法正常工作。
public void connect(String serial){
this.serialPort = null;
try {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serial);
if (portIdentifier.isCurrentlyOwned()) {
System.out.println("Port in use!");
} else {
System.out.println(portIdentifier.getName());
this.serialPort = (SerialPort) portIdentifier.open(
"ListPortClass", 300);
int b = this.serialPort.getBaudRate();
System.out.println(Integer.toString(b));
this.serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
// serialPort.setInputBufferSize(65536);
// serialPort.setOutputBufferSize(4096);
System.out.println("Opened " + portIdentifier.getName());
OutputStream mOutputToPort = this.serialPort.getOutputStream();
InputStream mInputFromPort = this.serialPort.getInputStream();
this.OutputToPort = mOutputToPort;
this.InputFromPort = mInputFromPort;
this.connected = true;
}
} catch (IOException ex) {
System.out.println("IOException : " + ex.getMessage());
} catch (UnsupportedCommOperationException ex) {
System.out.println("UnsupportedCommOperationException : " + ex.getMessage());
} catch (NoSuchPortException ex) {
System.out.println("NoSuchPortException : " + ex.getMessage());
} catch (PortInUseException ex) {
System.out.println("PortInUseException : " + ex.getMessage());}
}