Example usage for io.netty.channel.rxtx RxtxChannel config

List of usage examples for io.netty.channel.rxtx RxtxChannel config

Introduction

In this page you can find the example usage for io.netty.channel.rxtx RxtxChannel config.

Prototype

RxtxChannelConfig config

To view the source code for io.netty.channel.rxtx RxtxChannel config.

Click Source Link

Usage

From source file:com.whizzosoftware.wzwave.controller.netty.NettyZWaveController.java

License:Open Source License

public void start() {
    if (channel == null) {
        // set up Netty bootstrap
        bootstrap = new Bootstrap();
        bootstrap.group(new OioEventLoopGroup());
        bootstrap.channel(RxtxChannel.class);
        bootstrap.handler(new ChannelInitializer<RxtxChannel>() {
            @Override/*w  ww  . ja va2s  .  c  o m*/
            protected void initChannel(RxtxChannel channel) throws Exception {
                NettyZWaveController.this.channel = channel;
                channel.config().setBaudrate(115200);
                channel.config().setDatabits(RxtxChannelConfig.Databits.DATABITS_8);
                channel.config().setParitybit(RxtxChannelConfig.Paritybit.NONE);
                channel.config().setStopbits(RxtxChannelConfig.Stopbits.STOPBITS_1);
                channel.pipeline().addLast("decoder", new ZWaveFrameDecoder());
                channel.pipeline().addLast("ack", new ACKInboundHandler());
                channel.pipeline().addLast("encoder", new ZWaveFrameEncoder());
                channel.pipeline().addLast("writeQueue", new FrameQueueHandler());
                channel.pipeline().addLast("transaction", new TransactionInboundHandler());
                channel.pipeline().addLast("handler", inboundHandler);
            }
        });

        bootstrap.connect(new RxtxDeviceAddress(serialPort)).addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if (future.isSuccess()) {
                    sendDataFrame(new Version());
                    sendDataFrame(new MemoryGetId());
                    sendDataFrame(new InitData());
                } else {
                    onZWaveConnectionFailure(future.cause());
                }
            }
        });
    }
}