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

Thread: Does Serial.write() return the byte count?

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Location
    Utah
    Posts
    10

    Does Serial.write() return the byte count?

    If I have:

    uint16_t write_count;

    write_count = Serial.write(Buffer, length);

    I was expecting to have write_count show the number of bytes written. It does not. It's just zero. What should the correct behavior be here?

    (The reference pages shows it returns a byte [the source seems to show it returns a size_t, which I assume is uint32_t but I'm not sure]).

    Also, is there a good intro page into the magic behind the scenes in this Arduino environment? Is there a map file? Can I turn on compile logs, assembly listings and such so I can see what code is actually going into the build?

  2. #2
    Senior Member
    Join Date
    Jan 2013
    Location
    San Francisco Bay Area
    Posts
    641
    This is an old post, but I just ran into this issue. Serial.write always returns zero, even though I see data outputted in the serial monitor.
    If Serial.write() is guaranteed to send all bytes I guess it doesn't matter much. I was concerned though that maybe only a partial # of bytes were sent, and then I'd have to resend the remaining portion.

    Arduino page says it should return # of bytes sent:
    https://www.arduino.cc/en/Serial/Write

Posting Permissions

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