How to use RXTX with Netty 4?

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):

// 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();
+3
source share
1 answer

Finally he earned.

Turns out I find two different questions:

  • this program incorrectly checked exceptions / messages,
  • gnu.io gnu.io.PortInUseException: Unknown Application; ( - ) .

, /var/lock , .

- , , , : -)

+2

All Articles