[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rxtx
Subject:    Re: [Rxtx] Loading issues
From:       Ytai Ben-Tsvi <ytaibt () gmail ! com>
Date:       2012-06-23 20:59:54
Message-ID: CANfwwrAFkkSTDZmZU4dgOgo3sgZNL4RBsmw3E8EEe31L-11PMw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


@Oliver: You should never rely on that, since a raw serial protocol doesn't
have the notion of packets, and it's just an infinite stream of bytes. If
you're packets are variable size you should implement your own packet
mechanism on top, which can be as simple as <size> followed by <data>.
Your client code should wait for a full packet (or more) to be available,
read that one packet and handle it.

On Sat, Jun 23, 2012 at 1:24 PM, Oliver Rettig <Oliver.Rettig@orat.de>wrote=
:

> Hi,
>
> > Hi Oliver, I've never really encountered any problems with incoming
> > data when using RXTX or the Sun JavaComm predecessor. I always use the
> > SerialPortEventListener interface: set notifyOnDataAvailable,  and
> > upon SerialPortEvent.DATA_AVAILABLE just read all the available bytes
> > from the InputStream (up to the size of my raw data buffer array) with
> > a simple java.io.InputStream.read(byte[]) and never having to deal
> > with how much data is available.
> Ok, that=B4s a new idea for me. It sounds as a good idea always to read t=
he
> complete raw data buffer. But how can I get the size of the
> rawdatabuffer-size
> and how can I get it platform-independed. My device is connected via USB
> so I
> think the buffersize depends on the usb-serial-driver of the os.
>
> The device is streaming data every 20ms a data-block with a fixed length.
>  But
> can I be sure that for every SerialPortEvent.DATA_AVAILABLE I get a new
> data
> block starting at the beginning of the raw data buffer?
>
> The available function seems not to work correct. It get values which loo=
ks
> bigger than a raw data buffer size.So with read I get always more data th=
an
> the device has sendet.
>
> best regards
> Oliver
>
> > I believe it also works with a small
> > byte[] buffer - the SerialPortEvent.DATA_AVAILABLE must just fire
> > again. It just seems to always work. My serial data streams are quite
> > varied with various packet sizes, CRC techniques, etc., and we've used
> > the same techniques since at least 2001 when I joined the company. I
> > think I once posted a clean-room implementation of this technique
> > (rather than that under the copyright of my company).
> >
> > Regards,
> > Michael Erskine.
> > _______________________________________________
> > Rxtx mailing list
> > Rxtx@qbang.org
> > http://mailman.qbang.org/mailman/listinfo/rxtx
>
> _______________________________________________
> Rxtx mailing list
> Rxtx@qbang.org
> http://mailman.qbang.org/mailman/listinfo/rxtx
>

[Attachment #5 (text/html)]

<div dir="ltr">@Oliver: You should never rely on that, since a raw serial protocol \
doesn&#39;t have the notion of packets, and it&#39;s just an infinite stream of \
bytes. If you&#39;re packets are variable size you should implement your own packet \
mechanism on top, which can be as simple as &lt;size&gt; followed by \
&lt;data&gt;.<div>

Your client code should wait for a full packet (or more) to be available, read that \
one packet and handle it.<br><br><div class="gmail_quote">On Sat, Jun 23, 2012 at \
1:24 PM, Oliver Rettig <span dir="ltr">&lt;<a href="mailto:Oliver.Rettig@orat.de" \
target="_blank">Oliver.Rettig@orat.de</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Hi,<br> <div class="im"><br>
&gt; Hi Oliver, I&#39;ve never really encountered any problems with incoming<br>
&gt; data when using RXTX or the Sun JavaComm predecessor. I always use the<br>
&gt; SerialPortEventListener interface: set notifyOnDataAvailable,  and<br>
&gt; upon SerialPortEvent.DATA_AVAILABLE just read all the available bytes<br>
&gt; from the InputStream (up to the size of my raw data buffer array) with<br>
&gt; a simple java.io.InputStream.read(byte[]) and never having to deal<br>
&gt; with how much data is available.<br>
</div>Ok, thatīs a new idea for me. It sounds as a good idea always to read the<br>
complete raw data buffer. But how can I get the size of the rawdatabuffer-size<br>
and how can I get it platform-independed. My device is connected via USB so I<br>
think the buffersize depends on the usb-serial-driver of the os.<br>
<br>
The device is streaming data every 20ms a data-block with a fixed length.  But<br>
can I be sure that for every SerialPortEvent.DATA_AVAILABLE I get a new data<br>
block starting at the beginning of the raw data buffer?<br>
<br>
The available function seems not to work correct. It get values which looks<br>
bigger than a raw data buffer size.So with read I get always more data than<br>
the device has sendet.<br>
<br>
best regards<br>
<span class="HOEnZb"><font color="#888888">Oliver<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
&gt; I believe it also works with a small<br>
&gt; byte[] buffer - the SerialPortEvent.DATA_AVAILABLE must just fire<br>
&gt; again. It just seems to always work. My serial data streams are quite<br>
&gt; varied with various packet sizes, CRC techniques, etc., and we&#39;ve used<br>
&gt; the same techniques since at least 2001 when I joined the company. I<br>
&gt; think I once posted a clean-room implementation of this technique<br>
&gt; (rather than that under the copyright of my company).<br>
&gt;<br>
&gt; Regards,<br>
&gt; Michael Erskine.<br>
&gt; _______________________________________________<br>
&gt; Rxtx mailing list<br>
&gt; <a href="mailto:Rxtx@qbang.org">Rxtx@qbang.org</a><br>
&gt; <a href="http://mailman.qbang.org/mailman/listinfo/rxtx" \
target="_blank">http://mailman.qbang.org/mailman/listinfo/rxtx</a><br> <br>
_______________________________________________<br>
Rxtx mailing list<br>
<a href="mailto:Rxtx@qbang.org">Rxtx@qbang.org</a><br>
<a href="http://mailman.qbang.org/mailman/listinfo/rxtx" \
target="_blank">http://mailman.qbang.org/mailman/listinfo/rxtx</a><br> \
</div></div></blockquote></div><br></div></div>



_______________________________________________
Rxtx mailing list
Rxtx@qbang.org
http://mailman.qbang.org/mailman/listinfo/rxtx


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic