io.netty.channel.rxtx.RxtxDeviceAddress Java Examples

The following examples show how to use io.netty.channel.rxtx.RxtxDeviceAddress. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RxtxClient.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #2
Source File: RxtxClient.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #3
Source File: RxtxClientChannelManager.java    From openAGV with Apache License 2.0 5 votes vote down vote up
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());
    }
}