Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: USBHost_t36 last character of packet is undetected until next packet sent.

  1. #1
    Junior Member
    Join Date
    May 2021
    Posts
    4

    USBHost_t36 last character of packet is undetected until next packet sent.

    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*>(auchB uf), 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

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,452
    You may have found a bug in the library. But if you want me or anyone to investigate and fix it, you really do need to gives us complete programs to run on both Teensy 3.6 or 4.0 or 4.1 (can't tell which you're using on the host side) and also the code to run on the Teensy++ 2.0. Even if the code is "trivial", you need to show 2 complete programs anyone can copy into Arduino and upload to the 2 boards... without any guesswork to fill in the rest of the code!

  3. #3
    Junior Member
    Join Date
    May 2021
    Posts
    4
    That's all right. I found the bug in the library and fixed it.

  4. #4
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    265
    Quote Originally Posted by pmurphy View Post
    That's all right. I found the bug in the library and fixed it.
    You do intend to share the fix so that it can be permanently fixed for you & everyone else, right ??

    Mark J Culross

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •