public void connect(String portname, int baudrate, char flowControl) throws Exception {
Log.debug(this.getClass(), "connecting device "+portname+", "+baudrate+" baud");
boolean isCommonPortname = portname.contains("ttyS") || portname.contains("COM");
if ( ! isCommonPortname ) {
System.setProperty("gnu.io.rxtx.SerialPorts", portname);
}
System.setProperty("gnu.io.rxtx.NoVersionOutput", "true");
CommPortIdentifier commPortIdentifier = CommPortIdentifier.getPortIdentifier(portname);
CommPort commPort = commPortIdentifier.open("tc65sh", 2000);
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(baudrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.enableReceiveTimeout(2000);
if ( flowControl == FLOWCONTROL_NONE ) {
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
} else if ( flowControl == FLOWCONTROL_RTSCTS) {
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_OUT | SerialPort.FLOWCONTROL_RTSCTS_IN);
} else if ( flowControl == FLOWCONTROL_XONXOFF) {
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_XONXOFF_OUT | SerialPort.FLOWCONTROL_XONXOFF_IN);
} else {
throw new RuntimeException("invalid flowControl "+flowControl);
}
serialIn = serialPort.getInputStream();
serialOut = serialPort.getOutputStream();
}
Device.java 文件源码
java
阅读 31
收藏 0
点赞 0
评论 0
项目:tc65sh
作者:
评论列表
文章目录