I ran into a number of problems which I think are related to overflowing the Arduino serial buffer. So I thought I'd set up a handshaking protocol, where I send 30 bytes, wait for a character to come back from the Arduino, send another 30 bytes, repeat until done.
A far simpler technique would be to copy the 129 bytes into a buffer in your program.
The nature of serial data is such that you really should have a "start" byte, so if you happen to connect in mid-stream you are not out of sync.http://www.gammon.com.au/serial
the sketch knows it's received everything when it gets 129 bytes
Maybe. It knows it has received 129 bytes is about all.
// I thought this loop would "drain" the serial buffer, so the
// next pass through loop() -- before the Windows program reloads
// the Arduino's serial buffer -- curAvail would be 0. But that's not
// happening, it's always 1.
while( Serial.read() >= 0 )
That won't really "drain" the buffer if data is currently incoming, because it is still arriving, and you will execute that loop faster than the data arrives.
Almost always, when we find people trying to "drain" or "flush" the buffer, they are going about it the wrong way ... no offence.
Since you are writing both ends, send a "start" byte (eg. 0x01), and then the data, and then an end marker. (eg. 0x02). The Arduino end saves between the start and end marker into memory. Preferably also have a CRC check. Also make sure you don't overflow the buffer (in case you miss the end marker).
I wrote a simple library to do exactly that, described as part of this page:http://www.gammon.com.au/forum/?id=11428