3
我試圖使用Netty 4與RXTX(它不是正式在Netty 3.x,如果我得到這個權利)。如何在Netty 4上使用RXTX?
我想我已經設置了管道工廠正常,但是當一些數據發送到串行端口(我已確認與CoolTerm我沒有得到所產生的任何事件,有一些數據從我的設備經常進來)。
這裏是我用於測試(其中serialPort
是像/dev/tty.usbserial-A100MZ0L
(這是一個FTDI設備)下面的代碼:
// Configure the client.
final ExecutorService executorService = Executors.newCachedThreadPool();
RxtxChannelFactory rxtxChannelFactory = new RxtxChannelFactory(executorService);
ClientBootstrap bootstrap = new ClientBootstrap(rxtxChannelFactory);
// Set up the pipeline factory.
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
// Create and configure a new pipeline for a new channel.
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
pipeline.addLast("logger", new LoggerHandler());
return pipeline;
}
});
// Start the connection attempt.
ChannelFuture future = bootstrap.connect(new RxtxDeviceAddress(serialPort));
// Wait until the connection is made successfully.
Channel channel = future.awaitUninterruptibly().getChannel();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
boolean exit = false;
while (!exit) {
try {
String line = reader.readLine();
if ("exit".equals(line)) {
exit = true;
}
} catch (IOException e) {
// ignore
}
}
// Close the connection.
channel.close().awaitUninterruptibly();
// Shut down all thread pools to exit.
bootstrap.releaseExternalResources();