SerialConnection.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:Ardulink-1 作者:
/**
 * This method is used to get a list of all the available Serial ports
 * (note: only Serial ports are considered). Any one of the elements
 * contained in the returned {@link List} can be used as a parameter in
 * {@link #connect(String)} or {@link #connect(String, int)} to open a
 * Serial connection.
 * 
 * @return A {@link List} containing {@link String}s showing all available
 *         Serial ports.
 */
public List<String> getPortList() {
    List<String> ports = new ArrayList<String>();
    Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
        CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
        if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
            ports.add(portId.getName());
        }
    }
    writeLog("found the following ports:");
    for (String port : ports) {
        writeLog("   " + port);
    }

    return ports;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号