C
caimaani
Hi,
I am developing J2ME class that listens the serial port and reads all
available bytes from the buffer in a single read event. The number of
bytes and the structure of the message may vary very much (read: they
are undefined).
At the time I'm using InputStream.read() method to read the first byte
and to trigger InputStream.available() to find out how many bytes the
buffer still contains before I read them all. However it seems not to
be very reliable without some kind of delay because sometimes the
bytes are written to buffer so slowly (althought another component
does this in a single write event). So reading is triggered too
quickly and available() returns too small number.
How can I ensure that InputStream.available() gives me the real number
of bytes? Is it mandatory to add some kind of delay?
I am developing J2ME class that listens the serial port and reads all
available bytes from the buffer in a single read event. The number of
bytes and the structure of the message may vary very much (read: they
are undefined).
At the time I'm using InputStream.read() method to read the first byte
and to trigger InputStream.available() to find out how many bytes the
buffer still contains before I read them all. However it seems not to
be very reliable without some kind of delay because sometimes the
bytes are written to buffer so slowly (althought another component
does this in a single write event). So reading is triggered too
quickly and available() returns too small number.
How can I ensure that InputStream.available() gives me the real number
of bytes? Is it mandatory to add some kind of delay?