在android上使用CommPortIdentifier

时间:2013-09-16 18:09:01

标签: java android serial-port

我正在尝试在Android上使用CommPortIdentifier,但它给了我一个错误,这是我的代码:

Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();

CommPortIdentifier portId = null;

    while (portList.hasMoreElements()) {

        portId = portList.nextElement();

        if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

            //log.debug("Found port: " + portId.getName());

            if (portId.getName().equals(port)) {
                //log.debug("Using Port: " + portId.getName());
                found = true;
                break;
            }
        }
    }

它让我与Main崩溃:致命异常。

0 个答案:

没有答案