类io.netty.channel.rxtx.RxtxDeviceAddress源码实例Demo

下面列出了怎么用io.netty.channel.rxtx.RxtxDeviceAddress的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: netty-4.1.22   文件: RxtxClient.java
public static void main(String[] args) throws Exception {
    EventLoopGroup group = new OioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group)
         .channel(RxtxChannel.class)
         .handler(new ChannelInitializer<RxtxChannel>() {
             @Override
             public void initChannel(RxtxChannel ch) throws Exception {
                 ch.pipeline().addLast(
                     new LineBasedFrameDecoder(32768),
                     new StringEncoder(),
                     new StringDecoder(),
                     new RxtxClientHandler()
                 );
             }
         });

        ChannelFuture f = b.connect(new RxtxDeviceAddress(PORT)).sync();

        f.channel().closeFuture().sync();
    } finally {
        group.shutdownGracefully();
    }
}
 
源代码2 项目: netty4.0.27Learn   文件: RxtxClient.java
public static void main(String[] args) throws Exception {
    EventLoopGroup group = new OioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group)
         .channel(RxtxChannel.class)
         .handler(new ChannelInitializer<RxtxChannel>() {
             @Override
             public void initChannel(RxtxChannel ch) throws Exception {
                 ch.pipeline().addLast(
                     new LineBasedFrameDecoder(32768),
                     new StringEncoder(),
                     new StringDecoder(),
                     new RxtxClientHandler()
                 );
             }
         });

        ChannelFuture f = b.connect(new RxtxDeviceAddress(PORT)).sync();

        f.channel().closeFuture().sync();
    } finally {
        group.shutdownGracefully();
    }
}
 
源代码3 项目: openAGV   文件: RxtxClientChannelManager.java
public void connect(@Nonnull String host, int port) {
    requireNonNull(host, "host");
    checkState(isInitialized(), "Not initialized");
    if (isConnected()) {
        LOG.debug("Already connected, doing nothing.");
        return;
    }
    try {
        bootstrap.option(RxtxChannelOption.BAUD_RATE, port);
        channelFuture = bootstrap.connect(new RxtxDeviceAddress(host)).sync();
        channelFuture.addListener((ChannelFuture future) -> {
            if (future.isSuccess()) {
                this.initialized = true;
                LOG.info("串口连接并监听成功,名称[{}],波特率[{}]", host, port);
                connectionEventListener.onConnect();
            } else {
                connectionEventListener.onFailedConnectionAttempt();
                LOG.info("打开串口时失败,名称[" + host + "], 波特率[" + port + "], 串口可能已被占用!");
            }
        });
        connectFuture = null;
    } catch (Exception e) {
        e.printStackTrace();
        workerGroup.shutdownGracefully();
        throw new RuntimeException("RxtxClientChannelManager initialized is " + isInitialized() + ", exception message:  " + e.getMessage());
    }
}
 
 类所在包
 类方法
 同包方法