Skip to content
Tcl Source Code History Of Ticket 2953593
Login

History Of Ticket 2953593

Artifacts Associated With Ticket 2953593

  1. Ticket change [21566059e2] (rid 130567) by egavilan on 2010-02-17 15:12:52:

    1. assignee initialized to: "andreas_kupries"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Reading a serial port in nonblocking mode sometimes returns 0 for the number of bytes read.
      
      The [gets] documentation states "If varName is specified and an empty string is returned in varName because of end-of-file or because of insufficient data in non-blocking mode, then the return count is -1".
      
      In this case I expect either -1 or 10 (the length of the incoming message from the device, which never sends empty lines).
      
      The next script shows the issue:
      
      ===========================================================================
      proc readserial {fd} {
          global short empty normal
      
          set chars [chan gets $fd data]
          if {$chars == -1} {
              if {[chan eof $fd]} {
                  chan close $fd
                  done
              }
              incr short
              return
          }
          # this shouldn't happen, but it does anyway
          if {$chars == 0} {
              incr empty
              return
          }
          incr normal
          if {$normal == 10000} {
              done
          }
      }
      
      proc done {} {
          global short empty
          chan puts "Empty reads: $empty\nShort reads: $short"
          exit
      }
      
      set empty  0
      set short  0
      set normal 0
      
      set fd [open /dev/ttyUSB0 r]
      chan configure $fd \
          -mode 9600,n,8,1 \
          -buffering line \
          -blocking 0
      chan event $fd readable [list readserial $fd]
      ===========================================================================
      
      Notes:
      In blocking mode there's no "empty" reads.
      This happen in both windows and linux.
      The serial port is a usb<->serial adapter.
      The whole script has a Tk gui, showing the value read in a label.
      
    4. foundin initialized to: "None"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "egavilan"
    10. subsystem initialized to: "24. Channel Commands"
    11. title initialized to: "[gets $fd data] returns 0 in nonblocking mode"
    12. type initialized to: "Bug"
  2. Ticket change [5c55af6e26] (rid 115282) by ferrieux on 2010-03-02 21:37:30:

    1. icomment:
      strace appreciated ;-)
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  3. Ticket change [f5e82977a2] (rid 258315) by serhiy.storchaka on 2026-10-16 21:40:49:

    1. icomment:
      Not reproduced: CRLF, LF and CR input split at random points gives no unexpected empty lines (LF CR input gives an empty line for each CR in auto mode, as expected). Testing this found a regression in 8.6.13, reported as [4c5a98f5a0].
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
  4. Ticket change [7562e15fe4] (rid 258316) by serhiy.storchaka on 2026-10-16 21:44:20:

    1. icomment:
      Correction: this is the torn CRLF case of [b3977d199b] (CR and LF in different reads give an extra empty line in auto mode). It reproduces in 8.4.20 to 8.6.12 and was fixed in 8.6.13 by [a3ed092aab]. That check-in also caused [4c5a98f5a0].
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
    4. resolution changed to: "Fixed"
    5. status changed to: "Closed"
  5. Ticket change [f9330ab1bf] (rid 259952) by serhiy.storchaka on 2026-10-22 17:19:27:

    1. closedate changed to: "2461330.4057951965"
    2. closer changed to: "serhiy.storchaka"
    3. login: "serhiy.storchaka"