I am trying to use Netty 4 with RXTX (this is not official in Netty 3.x, if I understood correctly).
I think I configured the factory pipeline correctly, but I do not get any event that is generated when some data is sent to the serial port (I confirmed to CoolTerm that some data comes regularly from my device).
Below is the code I'm using for testing (where serialPortis something like /dev/tty.usbserial-A100MZ0L(this is an FTDI device):
final ExecutorService executorService = Executors.newCachedThreadPool();
RxtxChannelFactory rxtxChannelFactory = new RxtxChannelFactory(executorService);
ClientBootstrap bootstrap = new ClientBootstrap(rxtxChannelFactory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
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;
}
});
ChannelFuture future = bootstrap.connect(new RxtxDeviceAddress(serialPort));
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) {
}
}
channel.close().awaitUninterruptibly();
bootstrap.releaseExternalResources();
source
share