diff options
Diffstat (limited to 'doc/open.n')
-rw-r--r-- | doc/open.n | 105 |
1 files changed, 53 insertions, 52 deletions
@@ -19,7 +19,6 @@ open \- Open a file-based or command pipeline channel .br \fBopen \fIfileName access permissions\fR .BE - .SH DESCRIPTION .PP This command opens a file, serial port, or command pipeline and returns a @@ -43,22 +42,30 @@ Open the file for both reading and writing; the file must already exist. .TP 15 \fBw\fR -Open the file for writing only. Truncate it if it exists. If it doesn't +Open the file for writing only. Truncate it if it exists. If it does not exist, create a new file. .TP 15 \fBw+\fR Open the file for reading and writing. Truncate it if it exists. -If it doesn't exist, create a new file. +If it does not exist, create a new file. .TP 15 \fBa\fR -Open the file for writing only. If the file doesn't exist, +Open the file for writing only. If the file does not exist, create a new empty file. Set the file pointer to the end of the file prior to each write. .TP 15 \fBa+\fR -Open the file for reading and writing. If the file doesn't exist, +Open the file for reading and writing. If the file does not exist, create a new empty file. Set the initial access position to the end of the file. +.VS 8.5 +.PP +All of the legal \fIaccess\fR values above may have the character +\fBb\fR added as the second or third character in the value to +indicate that the opened channel should be configured with the +\fB\-translation binary\fR option, making the channel suitable for +reading or writing of binary data. +.VE 8.5 .PP In the second form, \fIaccess\fR consists of a list of any of the following flags, all of which have the standard POSIX meanings. @@ -75,9 +82,14 @@ Open the file for both reading and writing. .TP 15 \fBAPPEND\fR Set the file pointer to the end of the file prior to each write. +.VS 8.5 +.TP 15 +\fBBINARY\fR +Configure the opened channel with the \fB\-translation binary\fR option. +.VE 8.5 .TP 15 \fBCREAT\fR -Create the file if it doesn't already exist (without this flag it +Create the file if it does not already exist (without this flag it is an error for the file not to exist). .TP 15 \fBEXCL\fR @@ -104,18 +116,11 @@ If a new file is created as part of opening it, \fIpermissions\fR (an integer) is used to set the permissions for the new file in conjunction with the process's file mode creation mask. \fIPermissions\fR defaults to 0666. -.PP -Note that if you are going to be reading or writing binary data from -the channel created by this command, you should use the -\fBfconfigure\fR command to change the \fB-translation\fR option of -the channel to \fBbinary\fR before transferring any binary data. This -is in contrast to the ``b'' character passed as part of the equivalent -of the \fIaccess\fR parameter to some versions of the C library -\fIfopen()\fR function. - .SH "COMMAND PIPELINES" .PP -If the first character of \fIfileName\fR is ``|'' then the +If the first character of \fIfileName\fR is +.QW | +then the remaining characters of \fIfileName\fR are treated as a list of arguments that describe a command pipeline to invoke, in the same style as the arguments for \fBexec\fR. @@ -140,7 +145,6 @@ returned (a silent \fBclose\fR with -blocking 0). It is often useful to use the \fBfileevent\fR command with pipelines so other processing may happen at the same time as running the command in the background. -.VS 8.4 .SH "SERIAL COMMUNICATIONS" .PP If \fIfileName\fR refers to a serial port, then the specified serial port @@ -156,8 +160,14 @@ This option is a set of 4 comma-separated values: the baud rate, parity, number of data bits, and number of stop bits for this serial port. The \fIbaud\fR rate is a simple integer that specifies the connection speed. \fIParity\fR is one of the following letters: \fBn\fR, \fBo\fR, \fBe\fR, -\fBm\fR, \fBs\fR; respectively signifying the parity options of ``none'', -``odd'', ``even'', ``mark'', or ``space''. \fIData\fR is the number of +\fBm\fR, \fBs\fR; respectively signifying the parity options of +.QW none , +.QW odd , +.QW even , +.QW mark , +or +.QW space . +\fIData\fR is the number of data bits and should be an integer from 5 to 8, while \fIstop\fR is the number of stop bits and should be the integer 1 or 2. .TP @@ -165,19 +175,21 @@ number of stop bits and should be the integer 1 or 2. (Windows and Unix). This option is used to setup automatic handshake control. Note that not all handshake types maybe supported by your operating system. The \fItype\fR parameter is case-independent. -.sp +.RS +.PP If \fItype\fR is \fBnone\fR then any handshake is switched off. \fBrtscts\fR activates hardware handshake. Hardware handshake signals are described below. For software handshake \fBxonxoff\fR the handshake characters can be redefined -with \fB-xchar\fR. +with \fB\-xchar\fR. An additional hardware handshake \fBdtrdsr\fR is available only under Windows. There is no default handshake configuration, the initial value depends on your operating system settings. -The \fB-handshake\fR option cannot be queried. +The \fB\-handshake\fR option cannot be queried. +.RE .TP \fB\-queue\fR -(Windows and Unix). The \fB-queue\fR option can only be queried. +(Windows and Unix). The \fB\-queue\fR option can only be queried. It returns a list of two integers representing the current number of bytes in the input and output queue respectively. .TP @@ -186,7 +198,7 @@ of bytes in the input and output queue respectively. read operations. It specifies the maximum interval between the reception of two bytes in milliseconds. For Unix systems the granularity is 100 milliseconds. -The \fB-timeout\fR option does not affect write operations or +The \fB\-timeout\fR option does not affect write operations or nonblocking reads. This option cannot be queried. .TP @@ -197,13 +209,13 @@ The \fIsignal\fR names are case-independent. \fB{RTS 1 DTR 0}\fR sets the RTS output to high and the DTR output to low. The BREAK condition (see below) is enabled and disabled with \fB{BREAK 1}\fR and \fB{BREAK 0}\fR respectively. -It's not a good idea to change the \fBRTS\fR (or \fBDTR\fR) signal +It is not a good idea to change the \fBRTS\fR (or \fBDTR\fR) signal with active hardware handshake \fBrtscts\fR (or \fBdtrdsr\fR). The result is unpredictable. -The \fB-ttycontrol\fR option cannot be queried. +The \fB\-ttycontrol\fR option cannot be queried. .TP \fB\-ttystatus\fR -(Windows and Unix). The \fB-ttystatus\fR option can only be +(Windows and Unix). The \fB\-ttystatus\fR option can only be queried. It returns the current modem status and handshake input signals (see below). The result is a list of signal,value pairs with a fixed order, @@ -239,7 +251,6 @@ In case of a serial communication error, \fBread\fR or \fBputs\fR returns a general Tcl file I/O error. \fBfconfigure -lasterror\fR can be called to get a list of error details. See below for an explanation of the various error codes. - .SH "SERIAL PORT SIGNALS" .PP RS-232 is the most commonly used standard electrical interface for serial @@ -250,7 +261,6 @@ lines and handshaking. Here we are using the terms \fIworkstation\fR for your computer and \fImodem\fR for the external device, because some signal names (DCD, RI) come from modems. Of course your external device may use these signal lines for other purposes. - .IP \fBTXD(output)\fR \fBTransmitted Data:\fR Outgoing serial data. .IP \fBRXD(input)\fR @@ -270,8 +280,9 @@ serial port is opened. \fBData Set Ready:\fR The complement to DTR. Tells the workstation that the modem is ready to establish a link. .IP \fBDCD(input)\fR -\fBData Carrier Detect:\fR This line becomes active when a modem detects -a "Carrier" signal. +\fBData Carrier Detect:\fR This line becomes active when a modem detects a +.QW Carrier +signal. .IP \fBRI(input)\fR \fBRing Indicator:\fR Goes active when the modem detects an incoming call. .IP \fBBREAK\fR @@ -281,17 +292,15 @@ milliseconds. Normally a receive or transmit data signal stays at the mark (on=1) voltage until the next character is transferred. A BREAK is sometimes used to reset the communications line or change the operating mode of communications hardware. - .SH "ERROR CODES (Windows only)" .PP A lot of different errors may occur during serial read operations or during event polling in background. The external device may have been switched off, the data lines may be noisy, system buffers may overrun or your mode -settings may be wrong. That's why a reliable software should always +settings may be wrong. That is why a reliable software should always \fBcatch\fR serial read operations. In cases of an error Tcl returns a general file I/O error. Then \fBfconfigure -lasterror\fR may help to locate the problem. The following error codes may be returned. - .TP 10 \fBRXOVER\fR Windows input buffer overrun. The data comes faster than your scripts reads @@ -320,8 +329,6 @@ may cause this error. .TP 10 \fBBREAK\fR A BREAK condition has been detected by your UART (see above). -.VE - .SH "PORTABILITY ISSUES" .TP \fBWindows \fR(all versions) @@ -356,7 +363,8 @@ standard input from a pipe and send standard output to a pipe run synchronously. Command pipelines that do not execute 16-bit DOS applications run asynchronously and can be opened for both reading and writing. -.sp +.RS +.PP When running Tcl interactively, there may be some strange interactions between the real console, if one is present, and a command pipeline that uses standard input or output. If a command pipeline is opened for reading from @@ -369,7 +377,7 @@ console at the same time. If the command pipeline is started from a script, so that Tcl is not accessing the console, or if the command pipeline does not use standard input or output, but is redirected from or to a file, then the above problems do not occur. -.sp +.PP Whether or not Tcl is running interactively, if a command pipeline is opened for reading from a 16-bit DOS application, the call to \fBopen\fR will not return until end-of-file has been received from the command pipeline's @@ -377,22 +385,16 @@ standard output. If a command pipeline is opened for writing to a 16-bit DOS application, no data will be sent to the command pipeline's standard output until the pipe is actually closed. This problem occurs because 16-bit DOS applications are run synchronously, as described above. -.TP -\fBMacintosh\fR -Opening a serial port is not currently implemented under Macintosh. -.sp -Opening a command pipeline is not supported under Macintosh, since -applications do not support the concept of standard input or output. +.RE .TP \fBUnix\fR\0\0\0\0\0\0\0 Valid values for \fIfileName\fR to open a serial port are generally of the form \fB/dev/tty\fIX\fR, where \fIX\fR is \fBa\fR or \fBb\fR, but the name of any pseudo-file that maps to a serial port may be used. -.VS 8.4 Advanced configuration options are only supported for serial ports when Tcl is built to use the POSIX serial interface. -.VE 8.4 -.sp +.RS +.PP When running Tcl interactively, there may be some strange interactions between the console, if one is present, and a command pipeline that uses standard input. If a command pipeline is opened for reading, some @@ -402,9 +404,10 @@ both Tcl and the child application are competing for the console at the same time. If the command pipeline is started from a script, so that Tcl is not accessing the console, or if the command pipeline does not use standard input, but is redirected from a file, then the above problem does not occur. -.LP -See the PORTABILITY ISSUES section of the \fBexec\fR command for additional -information not specific to command pipelines about executing +.RE +.PP +See the \fBPORTABILITY ISSUES\fR section of the \fBexec\fR command for +additional information not specific to command pipelines about executing applications on the various platforms .SH "EXAMPLE" Open a command pipeline and catch any errors: @@ -415,11 +418,9 @@ if {[catch {close $fl} err]} { puts "ls command failed: $err" } .CE - .SH "SEE ALSO" file(n), close(n), filename(n), fconfigure(n), gets(n), read(n), puts(n), exec(n), pid(n), fopen(3) - .SH KEYWORDS access mode, append, create, file, non-blocking, open, permissions, pipeline, process, serial |