Let us say that my USB slave sends "Hello World\r\n"
My USB Host receiver:
while (USB.available() > 0) {
uint8_t auchBuf[512];
int cBytes(USB.readBytes(reinterpret_cast<char*>(auchBuf), constrain(USB.available(), 0, int(sizeof auchBuf))));
/* Note: cBytes/USB.available() reports strlen("Hello World\r\n") -1!! */
Serial.write(auchBuf, cBytes); //prints "Hello World\r" Note missing \n
}
Subsequent call to USB.available() report no new data.
Slave sends another "Hello World\r\n";
readBytes reads "\nHello World\r" // Note missing \n has now been received but final \n is once again missing from received packet.
Subsequent calls to USB.available() report no new data.
Until next packet is sent, at which time the missing \n is returned as the first octet in the packet and the final \n goes undetected.
It appears that the last octet received is stuck in the receive buffer, but undetected, or more likely an off by one error.
I tried issuing a read() after the readbytes(), but the read() timed out.
I tried this with a USB slave device, and a teensy 2++ as the slave device; The results were the same for both.
Patrick
My USB Host receiver:
while (USB.available() > 0) {
uint8_t auchBuf[512];
int cBytes(USB.readBytes(reinterpret_cast<char*>(auchBuf), constrain(USB.available(), 0, int(sizeof auchBuf))));
/* Note: cBytes/USB.available() reports strlen("Hello World\r\n") -1!! */
Serial.write(auchBuf, cBytes); //prints "Hello World\r" Note missing \n
}
Subsequent call to USB.available() report no new data.
Slave sends another "Hello World\r\n";
readBytes reads "\nHello World\r" // Note missing \n has now been received but final \n is once again missing from received packet.
Subsequent calls to USB.available() report no new data.
Until next packet is sent, at which time the missing \n is returned as the first octet in the packet and the final \n goes undetected.
It appears that the last octet received is stuck in the receive buffer, but undetected, or more likely an off by one error.
I tried issuing a read() after the readbytes(), but the read() timed out.
I tried this with a USB slave device, and a teensy 2++ as the slave device; The results were the same for both.
Patrick