return value of usb_serial_write()

Status
Not open for further replies.

tveenker

Member
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.
 
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/4089...ial-write()-on-Teensy-3-6?p=127732#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
 
Status
Not open for further replies.
Back
Top