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

Thread: return value of usb_serial_write()

  1. #1

    return value of usb_serial_write()

    Hi all,

    With arduino-1.6.3 and Teensyduino 124 the return value of calls usb_serial_write() is -1 on error and 0 on success. This matches what it says here: https://www.pjrc.com/teensy/usb_serial.html

    Now I've upgraded to arduino-1.8.4 and Teensyduino 139. I saw my Teensy code behave badly because the return value of usb_serial_write() has been changed (I tested for error by checking ret!=0 in stead of ret==-1). The function still yields -1 on error but on success it now yields the number of bytes passed to the method. So the documentation for usb_serial_write() on https://www.pjrc.com/teensy/usb_serial.html is incorrect.

    On https://www.pjrc.com/teensy/td_download.html I see under Version 1.36: "Hardware serial write() compatibility fix". I assume that's the change I'm seeing. Are there a more detailed release notes available? That would have saved me some debugging.

    Another thing. Would it be possible to have the arduino/teensyduino version numbers available somewhere in a header file? That would allow one to work around incompatible changes between versions.

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,767
    I think it changed almost a year ago with Pull request: https://github.com/PaulStoffregen/cores/pull/202
    Which mentions the thread:
    https://forum.pjrc.com/threads/40893...732#post127732

    The Arduino build environment does define a version you can look for, if you do a verbose build you will see that the commands to build include:
    -DTEENSYDUINO=140 -DARDUINO=10805

    So you can test for the define TEENSYDUINO which in my case is on build 140 and I am on Arduino build 1.8.5

  3. #3
    Quote Originally Posted by KurtE View Post
    So you can test for the define TEENSYDUINO which in my case is on build 140 and I am on Arduino build 1.8.5
    Ah of course. Didn't think of that. Thanks.

    I do think the info on https://www.pjrc.com/teensy/usb_serial.html should be updated to reflect the actual situation.

Posting Permissions

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