Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Deleted my other "answer" about the CRC because I don't think that is the problem. Dan mentioned in a comment that he got the code from <a href="http://trackday.cc/b2evo/blog2.php/2007/08/02/net-xmodem" rel="nofollow">http://trackday.cc/b2evo/blog2.php/2007/08/02/net-xmodem</a>. The code pasted in the original question comes directly from that source.</p> <p>I downloaded it and started looking it over. It has a lot of flaws(*), mostly non-fatal. However, this part jumped out at me in the XModemReceive method:</p> <pre><code>#region fill packet with datastream xbuff[0] = (byte)c; for (i = 0; i &lt; (bufsz + (useCRC ? 1 : 0) + 3); i++) { xbuff[i + 1] = (byte)this.port.ReadByte(); } #endregion </code></pre> <p>If SerialPort.ReadByte encounters End Of Stream it will return -1 (i.e. 255 in byte form). If ReadByte had timed out, a TimeoutException would occur. If EOS is encountered, the correct course of action might be to abort the current packet. I have not spent any time thinking that through.</p> <p>First I would alter that code just to test if this is in fact the problem you're seeing:</p> <pre><code>xbuff[0] = (byte)c; for (i = 0; i &lt; (bufsz + (useCRC ? 1 : 0) + 3); i++) { int byteValue = this.port.ReadByte(); Debug.Assert(byteValue &gt;= 0, "byteValue &gt;= 0"); xbuff[i + 1] = (byte)byteValue; } </code></pre> <p>That is not a fix, just a test. If it is asserting (in a Debug build), than we can think about fixing it.</p> <p>(*) I <a href="http://tergiver.wordpress.com/2011/03/13/whats-wrong-with-this-code/" rel="nofollow">blogged</a> about the first few 'flaws' if you're interested in reading about them.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload