netty rxtx 不能与 NioEventLoopGroup 一起工作

netty rxtx can not work with NioEventLoopGroup

netty rxtx 无法与 NioEventLoopGroup 一起使用。 使用 Oio 时还可以,并且工作正常,但是更改为 Nio 时代码无法运行。 这个项目有很多 rial 端口连接。 RXTX 仅适用于 oio?

Netty 4.1.6,Java1.8.0_112

EventLoopGroup event = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();

bootstrap.group(event);
bootstrap.channel(RxtxChannel.class);
bootstrap.remoteAddress(new RxtxDeviceAddress(device.getSerialPort()));
// 设置端口参数
if (device.getSerialBaudRate() > 0)
    bootstrap.option(RxtxChannelOption.BAUD_RATE, device.getSerialBaudRate());

// bootstrap.option(RxtxChannelOption.DATA_BITS,
// RxtxChannelConfig.Databits.DATABITS_8);
// bootstrap.option(RxtxChannelOption.STOP_BITS,
// RxtxChannelConfig.Stopbits.STOPBITS_1);
// bootstrap.option(RxtxChannelOption.PARITY_BIT,
// RxtxChannelConfig.Paritybit.NONE);
// bootstrap.option(RxtxChannelOption.READ_TIMEOUT, 3000);
// 等待时间量
// bootstrap.option(RxtxChannelOption.WAIT_TIME, 100);
// bootstrap.option(RxtxChannelOption.DTR, false);
// bootstrap.option(RxtxChannelOption.RTS, false);

bootstrap.handler(new ChannelInitializer<RxtxChannel>() {
    @Override
    protected void initChannel(RxtxChannel sc) throws Exception {
    ChannelPipeline pipeline = sc.pipeline();
    // 空闲时间监测(秒)
    pipeline.addLast(new IdleStateHandler(120, 60, 60));
    // 创建基于报头和长度的解码器
    pipeline.addLast(new KSFrameLengthDecoder());
    pipeline.addLast(new KSFrameDecoder(coder));
    // 创建业务逻辑解码器
    pipeline.addLast(new SimpleChannelInboundHandler<Message>() {
        @Override
        public void channelActive(ChannelHandlerContext ctx) {
        busy.set(true);
        Message msg = Message.newBuilder().setCommand(Command.CONNECT).build();
        msg.device = device;
        channel.writeAndFlush(msg);
        }

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
        received(msg);
        if (queue.isEmpty()) {
            busy.set(false);
        } else {
            channel.writeAndFlush(queue.poll());
        }
        }

        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent e = (IdleStateEvent) evt;
            if (e.state() == IdleState.READER_IDLE) {
            restart();
            } else {
            busy.set(true);
            Message msg = Message.newBuilder().setCommand(Command.GET_DEVICE_DATE).build();
            msg.device = device;
            channel.writeAndFlush(msg);
            }
        }
        }

        // 异常
        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        // 出现异常时,记录错误,稍后重连
        Log.error(cause);
        restart();
        }
    });
    pipeline.addLast(new KSFrameEncoder(coder));
    }
});
ChannelFuture future = bootstrap.connect();
channel = future.channel();

Log.info("START" + device.getName());

是的 rxtx 仅适用于 OIO,因为它的实现使用了阻塞 InputStream 和 OutputStream。