Instruct Tcl to always send output to stdout immediately, whether or not it is to a terminal:
chan configure stdout -buffering none
Instruct Tcl to read pure bytes from a channel and write bytes to it, rather than characters:
chan configure $binaryDataFile -translation binary
The real name of the binary encoding is iso8859-1. -encoding binary was introduced as a migration aid to help with either the 7.6 -> 8.0 or the 8.0 to 8.1 transitions.
iso8859-1 has the privileged relationship with Unicode that its code-points are in a one-to-one relationship with \u0000-\u007f
Caveat: -encoding binary turns off -translation, but -encoding iso8859-1 does not.
When a string is put into a binary channel, only the lower 8 bits of each character are used, with the exception of Tcl's internal encoding of the null character, which is converted to a single-byte null character.
RS 2015-04-13 - On Windows 7, stdout (if not redirected) breaks in a funny way when the encoding is changed - notice the "%" prompt:
D:\>Tcl85\bin\tclsh % fconfigure stdout -encoding utf-8 ‥ ‥^C D:\>Tcl86\bin\tclsh % fconfigure stdout -encoding utf-8 ‥exit
With longer output, the whole console (Cygwin bash in cmd.exe) freezes and can only be closed, but no longer be used. In cmd.exe without Cygwin, Ctrl-C makes the console responsive again.
A workaround in both cases is to pipe stdout through cat. When stdout is redirected to a file, the problem is likewise not seen.
This behavior was not the case in Tcl 8.4:
D:\>Tcl84\bin\tclsh % fconfigure stdout -encoding utf-8 %
DKF: This is a consequence of the special channel type used to handle the console on Windows (which uses direct writing to the console API using unicode characters). It's encoding should not be changed, but we can't prevent that from happening without extra magic to let channel types veto changes to generic properties (something that currently isn't supported).
Tcl 8.4 “worked” because it was doing the wrong thing entirely that just happened to be more resistant to this problem.
LV 2008 Feb 28:
Some of the wiki pages talk about the construct,
chan configure $serial_port -mode "$baudRate,$plex,$bits,$polarity"
or some such thing. The -mode flag, used for specifying baud rate, etc, has moved to open now. I don't know how one would change those values on an open descriptor...