0

I'm having a hard time figuring out how to properly use the RXTX transport (from Git as of today).

I'm able to write inbound handlers which consumes content read from the serial port, decode it, and send some other content to the serial port via a custom outboundhandler. So far fine.

Now, there is a use-case where I need to write a message through a MessageToByteEncoder (the same custom outboundhandler I talked about before) from the main program (in the end, this will actually be a library using Netty underneath). So basically, I'm trying to do the same as the above scenario except I don't go through the decoders and send the message to be written from the main program and not an inbound handler. This scenario does not seem to work in my case: nothing seems to happen, as if my message was not sent. Unfortunately, there is not a lot of log statements in Netty and I may be wrong but the issue I have may surface because the main thread is not in the event loop (no surprise here! :)).

Unfortunately, the RXTX example only write messages from an inbound handler (via the ChannelHandlerContext), so I can't find out what I'm doing wrong or if there is a bug to this really recent addition in Netty.

Any suggestions?

jeje
  • 61
  • 4
  • Actually, I investigated the issue a litte bit more. I wrote an Arduino sketch sending back "OK" when sent the "AT\n" string. So far fine, I could check that through the serial monitor. I then simply changed the Rxtx example in order to specify the correct serial port and the correct bauds rate. I can see that the Arduino receives something, but I get stuck in the RxtxChannel.doReadBytes() method when buf.writeBytes(in, buf.writableBytes()) is called... – jeje Jan 18 '13 at 14:50
  • Hum. I may have found the problem: I can make this work if I run in debug mode with a breakpoint in RxtxChannel.doConnect(). I suppose that there is a race condition or that a wait is needed somewhere... – jeje Jan 18 '13 at 15:11
  • Actually, I can now confirm this: if I add something like Thread.sleep(5000) just after cpi.open(getClass().getName(), 1000) it works fine! – jeje Jan 18 '13 at 15:17

2 Answers2

0

You should be able to just write it with one of these two ways:

Channel channel = ...
channel.write(YourMessage);

ChannelHandlerContext ctx = ...
ctx.write(YourMessage)
Norman Maurer
  • 23,104
  • 2
  • 33
  • 31
  • The first option is the one I use. I can't make it work properly. No error at runtime, but it is as if my message want not written. How can I use the second option? Should I create my own context? If so from what? I only have the channel from the future after I connect. – jeje Jan 16 '13 at 14:59
0

The issues I had were actually linked to two different problems.

I found a fix for both of them (as one could have expected, the issues were in the RXTX transport itself):

jeje
  • 61
  • 4