SerialRXTXComm.java 文件源码

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

项目:meshnet 作者:
public SerialRXTXComm(CommPortIdentifier portIdentifier, Layer3Base layer3) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException, TooManyListenersException{

        if (portIdentifier.isCurrentlyOwned()) {
            throw new IOException("Port is currently in use");
        } else {
            CommPort commPort = portIdentifier.open(this.getClass().getName(),
                    TIME_OUT);

            if (commPort instanceof SerialPort) {
                SerialPort serialPort = (SerialPort) commPort;
                serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
                        SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

                inStream = serialPort.getInputStream();
                outStream = serialPort.getOutputStream();

                new SerialReceiver().start();

                /*serialPort.addEventListener(this);
                serialPort.notifyOnDataAvailable(true);*/

            } else {
                throw new IOException("This is not a serial port!.");
            }
        }

        this.layer2 = new Layer2Serial(this, layer3);
    }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号