I have just downloaded the Java Comm stuff including RXTX and noticed
that many of the functions aren't available. i.e addEventListener. Since
the Solaris examples use event listeners I have been trying to add this
functionality.
I have started doing this in an unsophisticated way by using a separate
thread based on the rx.java example to monitor the port. This thread
checks the port and generates a SerialPortEvent if any data appears.
Unfortunately there is no easy way to check the port for data without
reading it. Therefore I have added a single character buffer to
SerialImp.c so that I can implement the available() function. The main
problem I have is that even though I open the port as NONBLOCK in
SerialImp.c the port actual blocks on a read. I have tested the code
using a simple c program and the nonblocking stuff works fine. However
running under java it blocks, even though the flags are correct, checked
just before the read.
Does anybody know why the read function would block under java ?? (I'm
not sure if "under java" is exactly the right expression).
I can get the functionality working as long as the main line doesn't
call available() and just relies on an event as the monitor thread can
afford to block on the read. This is not satisfactory though and at non
blocking read is preferable or a way of finding out when the serial port
has data.
Any ideas ?
Dave Atkinson