Java 类io.netty.channel.rxtx.RxtxChannel 实例源码
项目:JavaAyo
文件: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();
}
}
项目: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();
}
}
项目:javase-study
文件: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();
}
}
项目:netty4study
文件: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("/dev/ttyUSB0")).sync();
f.channel().closeFuture().sync();
} finally {
group.shutdownGracefully();
}
}
项目:netty-netty-5.0.0.Alpha1
文件: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("/dev/ttyUSB0")).sync();
f.channel().closeFuture().sync();
} finally {
group.shutdownGracefully();
}
}
项目:waterrower-core
文件:RxtxCommunicationService.java
/**
* A communication service that manages the serial connection.
* It can receive and send serial messages via RXTX.
*
* @param bootstrap The bootstrap, not null.
* @param channelInitializer The channel initializer, not null.
*/
public RxtxCommunicationService(Bootstrap bootstrap, RxtxChannelInitializer channelInitializer) {
requireNonNull(bootstrap);
requireNonNull(channelInitializer);
this.bootstrap = bootstrap;
this.bootstrap.group(new OioEventLoopGroup());
this.bootstrap.channel(RxtxChannel.class);
channelInitializer.setRxTxSerialHandler(serialHandler);
this.bootstrap.handler(channelInitializer);
}
项目:waterrower-core
文件:RxtxChannelInitializer.java
@Override
protected void initChannel(RxtxChannel channel) throws Exception {
Log.debug(SERIAL, "RXTX channel initialized. Configuring pipeline and channel...");
checkIfRxTxSerialHandlerIsSet();
configureChannel(channel);
configurePipeline(channel);
}
项目:waterrower-core
文件:RxtxChannelInitializer.java
private void configureChannel(RxtxChannel channel) {
RxtxChannelConfig config = channel.config();
config.setBaudrate(19200);
config.setDatabits(DATABITS_8);
config.setStopbits(STOPBITS_1);
config.setParitybit(NONE);
logSerialConfiguration(config);
}
项目:waterrower-core
文件:RxtxChannelInitializer.java
private void configurePipeline(RxtxChannel channel) {
ChannelPipeline pipeline = channel.pipeline();
// Decode messages:
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(MAX_FRAME_LENGTH, lineDelimiter()));
pipeline.addLast("decoder", new RxtxMessageFrameDecoder(parser));
// Encode messages:
pipeline.addLast("encoder", new RxtxMessageFrameEncoder(parser));
// Handle messages and exceptions:
pipeline.addLast("handler", serialHandler);
Log.debug(SERIAL, "Pipeline configured and handler added.");
}