Ok I think the problem is SerialUSB1.readBytes() itself. I am sending a big chunk of 32K bytes from pc.
Code:
int handleDataTransfer(){
unsigned char bytecount = 0;
int rd=SerialUSB1.available();
if( rd>0 ) {
DLOG1("available bytes: %i \r\n",rd);
toggle=!toggle;
digitalWriteFast(TESTPin,toggle);
bytecount= SerialUSB1.readBytes(readBuffer,200);
DLOG1("read bytes: %i \r\n",bytecount);
if(bytecount>0){
ProcessInput(readBuffer,bytecount);
}
}
}
if I limit the number of bytes to read at 200, then everything is OK. This is the output:
Code:
available bytes: 512
read bytes: 200
pointer=0
available bytes: 312
read bytes: 200
pointer=200
available bytes: 624
read bytes: 200
pointer=400
available bytes: 936
read bytes: 200
pointer=600
available bytes: 1248
read bytes: 200
pointer=800
available bytes: 1560
read bytes: 200
pointer=1000
But if I try to read 512 bytes, which is what becomes available each time:
Code:
int handleDataTransfer(){
unsigned char bytecount = 0;
int rd=SerialUSB1.available();
if( rd>0 ) {
DLOG1("available bytes: %i \r\n",rd);
toggle=!toggle;
digitalWriteFast(TESTPin,toggle);
bytecount= SerialUSB1.readBytes(readBuffer,rd);
DLOG1("read bytes: %i \r\n",bytecount);
if(bytecount>0){
ProcessInput(readBuffer,bytecount);
}
}
}
the output is:
Code:
available bytes: 512
read bytes: 0
available bytes: 512
read bytes: 0
available bytes: 512
read bytes: 0
available bytes: 512
read bytes: 0
available bytes: 512
read bytes: 0
available bytes: 512
read bytes: 0
available bytes: 512
read bytes: 0
available bytes: 512
read bytes: 0
nothing read in by the function SerialUSB1.readBytes