@SuppressWarnings("unchecked")
private CommPortIdentifier findSerialPortIdentifier() throws PlugwiseInitializationException {
Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier identifier = portList.nextElement();
if (identifier.getPortType() == CommPortIdentifier.PORT_SERIAL
&& identifier.getName().equals(configuration.getSerialPort())) {
logger.debug("Serial port '{}' has been found", configuration.getSerialPort());
return identifier;
}
}
// Build exception message when port not found
StringBuilder sb = new StringBuilder();
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier id = portList.nextElement();
if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
sb.append(String.format("%s%n", id.getName()));
}
}
throw new PlugwiseInitializationException(String.format(
"Serial port '%s' could not be found. Available ports are:%n%s", configuration.getSerialPort(), sb));
}
PlugwiseCommunicationContext.java 文件源码
java
阅读 15
收藏 0
点赞 0
评论 0
项目:openhab2-addons
作者:
评论列表
文章目录