-
-
Notifications
You must be signed in to change notification settings - Fork 15.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RXTX: provide a wait option after opening the serial port #957
Conversation
I'm not sure why this pause might be needed for some devices, but this is at least something which works with the devices I had trouble with. One of the "known" device is an Arduino on Mac OS X (Lion). Perhaps the virtual serial device is too slow compared to "native" ones.
Blocking the core thread here seems a little bit scary. Would it be better to create a new class, RxtxUnsafe (extending AbstractUnsafe) that instead of calling Thread.sleep() schedules with its eventLoop() the initialisation of the serial port? |
I'm not sure I fully understand what you mean. What code would you put in the RxtxUnsafe class? Maybe I could simply create a Runnable with the code after the sleep and in the actual connect() method simply do something like:
|
How would you do it in an handler? I can't see how you'd enable a handler to "inject" some wait between those two steps of the channel :-( |
@jeje so the problem is that before the timeout elapsed it return null for the InputStream ? |
This is actually weirder than that: both in and out are non-null, but then we can't send any message to the serial port... |
How it fails ? Sent from my iPhone. Excuse any typos.... Am 21.01.2013 um 08:34 schrieb Jerome Bernard notifications@github.com:
|
Well, the RXTX example simply sends an "AT\n" command on the serial port and waits for an "OK\n" string to exit. From what I see on the Arduino RX/TX activity LEDs, the RXTX example does seem to send something (RX lights up for a short time) but nothing is sent back (no TX LED turned on). But I know for sure that my Arduino sketch is okay because when adding the wait time, it works fine!! When adding breakpoints on I tried changing baud rate (9600 instead of 57600) on both the RXTX example and the Arduino sketch but this does not change anything to the issue. I also tried with various waits in the Arduino sketch but nothing works. |
I've had a look into this using some of the serial devices I have (mainly GSM modems) available to me, and have been able to reproduce the problem with certain microcontrollers. The sequence events goes something like this:
This is very easily repeatable - I've tried various different wait timeouts, and 1s - 1.5s seems to be the minimum bound before the microcontroller has finished resetting and is capable of receiving data. However, the sleep doesn't need to be in the connect phase; I was able to make it work by putting the sleep in the handler in all cases. @jeje Can you try putting the sleep() in before the first write and see if that works? |
I wonder if this also is fixed by #962 ... Could both of you retest with latest master ? |
I can confirm that #962 does not help on this issue. Also, I tried with a modified RXTXClientHandler doing I did also another test by modifying RXTXClient right after
This does not work too, but in this last case, there is no RX LED activity... |
Boo :( I do wonder then if this is due to the arduino requiring a delay before the configuration options are coordinated too, in which case we do potentially need a pause of some kind between the open and the init. I'll do a pull request that shouldn't block the eventLoop main thread... |
…the serial port but before configuration to allow the serial microcontroller to reset itself after opening.
@jeje please retest with latest master and report back.. thanks! |
Works fine! Thanks to both of you @normanmaurer and @lw346 |
I'm not sure why this pause might be needed for some devices, but this
is at least something which works with the devices I had trouble with.
One of the "known" device is an Arduino on Mac OS X (Lion). Perhaps the
virtual serial device is too slow compared to "native" ones.