[Rxtx] Lingering rxtx process
George H
george.dma at gmail.com
Thu Feb 25 02:41:46 MST 2010
With Mariusz Dec help and with the help of the threads that were mentioned
http://mailman.qbang.org/pipermail/rxtx/2009-November/5790326.html
http://embeddedfreak.wordpress.com/2008/10/08/rxtx-serial-port-helper/
I managed to solved my problem. I didn't really like it so much. I am not
using the InputStream.read(byte[], int, int) method as for me I can break
out of reading the stream if I get a '\n' or a 0x00. Either way the below
code sample works for me.
int data = 0;
int len = 0;
while(true) {
data = commReader.getInputStream().read();
if(data == -1 || data == 0x00 || data == '\n' ||
commReader.getInputStream().available() < 1) {
break;
}
if(len == buffer.length) {
processData(buffer);
clearBuffer();
}
buffer[len++] = (byte)data;
}
Before I would loop the while until data != -1. But that blocks on .close()
and my program never gets to exit.
Adding .available() < 1 as a break condition fixes it when I call .close()
I am going to see if this is a linux kernel configuration issue or not cos
it isn't so obvious and I hardly ever use .available() when reading
streams.
Love the project though :)
--
George H
george.dma at gmail.com
On Tue, Feb 23, 2010 at 10:29 AM, Mariusz Dec <mariusz.dec at gmail.com> wrote:
>
>
> 2010/2/22 George H <george.dma at gmail.com>
>
> Hi,
>>
>> I am using RXTX v2.1-7.
>> I use it to communicate with 2 serial receipt printers and 1 serial line
>> display device. My program runs well using the RXTX library on Windows and
>> Linux.
>> But... when I installed Linux on another hardware the program does not
>> exit properly. By this I mean that the java program seems to have exited
>> (passed the System.exit(0)) code but the console still does not return to
>> the bash shell.
>>
>> Thread in Noember 2009' -
>
> http://mailman.qbang.org/pipermail/rxtx/2009-November/5778408.html
>
> I have disocvered one technique which solved this problem in Linux Ubuntu
> and Mac for RXTX pre2.2, but should helps in 2.1.7 as well.
>
> Regards
> Mariusz
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qbang.org/pipermail/rxtx/attachments/20100225/d609e517/attachment-0714.htm>
More information about the Rxtx
mailing list