如何将RXTX与Netty 4一起使用?
我正在尝试将Netty 4与RXTX一起使用(如果我没有弄错的话,它在Netty 3.x中还不是正式的) 我想我已经正确地设置了管道工厂,但是当一些数据被发送到串行端口时,我没有得到任何生成的事件(我已经与CoolTerm确认有一些数据定期从我的设备进入) 下面是我用于测试的代码(其中如何将RXTX与Netty 4一起使用?,netty,rxtx,Netty,Rxtx,我正在尝试将Netty 4与RXTX一起使用(如果我没有弄错的话,它在Netty 3.x中还不是正式的) 我想我已经正确地设置了管道工厂,但是当一些数据被发送到串行端口时,我没有得到任何生成的事件(我已经与CoolTerm确认有一些数据定期从我的设备进入) 下面是我用于测试的代码(其中serialPort类似于/dev/tty.usbserial-A100MZ0L(这是一个FTDI设备): 终于成功了 结果,我遇到了两个不同的问题: 此程序未正确检查/报告异常 我在gnu.io报告gnu.io.
serialPort
类似于/dev/tty.usbserial-A100MZ0L
(这是一个FTDI设备):
终于成功了 结果,我遇到了两个不同的问题:
gnu.io
报告gnu.io.portinuseeexception:Unknown Application
错误时遇到问题(我的博客帮助了我自己——这是第一次),但忘了对我的笔记本电脑进行修复/var/lock
目录,并使其可供运行程序的用户写入
如果有人建议如何检查我得到的异常,并适当地通知运行程序的用户,那就太好了:-)
// 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();