Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 6169669edafe69e16477b6bb0b0fc3daeba8f1f6
Ticket: 2913585fffffffffffffffffffffffffffffffff
[win32] serial channel blocks indefinitely on write
User & Date: a_kovalenko on 2009-12-13 08:35:32
Changes

  1. assignee changed to: "andreas_kupries"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    1. set fd [ open COM5: r+]
        fconfigure $fd -blocking no
        puts $fd something
        close $fd
    Hangs indefinitely in SerialBlockingWrite() when the port is not connected.
    2. if we use -blocking yes instead, close $fd seems to succeed, but _leaves an open handle and a running SerialWriterThread_ forever: so we get "permission denied" when trying to reopen the port.
    
    Write timeout is ignored on Windows (it's documented at the open man page, and also obvious from the code).
    
    The error is fixable in many ways, of which I can't select the best one yet. The problem is that GetOverlappedResult() in SerialBlockingWrite() waits forever (an interesting thing is that the code below handles ERROR_COUNTER_TIMEOUT, though it can never really happen). Forwarding the write timeout to SetCommTimeouts() would at least give me an ability to close the port somehow. Ensuring that the handle is not open after successful [close $fd], whether  its mode is blocking or non-blocking, would also be a good practice (thus avoiding the awful non-blocking case described above, when the handle is inaccessible by TCL but continues to hold the device in busy state). 
    
    Also, [chan cancel] for all pending IO would be a good addition, but it's more about long-term TCL development plans.
    
    It may happen that there is an easy workaround for _usual_ (UART16550A PC) serial ports: putting them into -handshake none mode, when all pending writes should succeed immediately. However, it doesn't help with many other COMM devices, like com0com-forwarded channels, Bluetooth virtual serial ports and (maybe) some USB2RS232 adaptors. This difference explains why this error could live unnoticed for so long.
    
  4. foundin changed to: "obsolete: 8.6b1.1"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "a_kovalenko"
  10. subsystem changed to: "25. Channel System"
  11. title changed to:
    [win32] serial channel blocks indefinitely on write
    
  12. type changed to: "Bug"