blob: 2cb2b034d0b346f3bdefe4f850f0b452dd1da2d2 [file] [log] [blame]
Fred Drakec817e271998-08-10 18:40:22 +00001\section{\module{ctb} ---
Fred Drakef6863c11999-03-02 16:37:17 +00002 Interface to the Communications Tool Box}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00003
Fred Drakef6863c11999-03-02 16:37:17 +00004\declaremodule{builtin}{ctb}
5 \platform{Mac}
Fred Drakef459a092000-10-14 04:49:36 +00006\modulesynopsis{Interfaces to the Communications Tool Box. Only the
7 Connection Manager is supported.}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00008
Jack Jansendcb0a9b1995-03-01 14:05:27 +00009
10This module provides a partial interface to the Macintosh
11Communications Toolbox. Currently, only Connection Manager tools are
Guido van Rossum96628a91995-04-10 11:34:00 +000012supported. It may not be available in all Mac Python versions.
Fred Drake41788db1998-04-04 06:23:02 +000013\index{Communications Toolbox, Macintosh}
14\index{Macintosh Communications Toolbox}
15\index{Connection Manager}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000016
17\begin{datadesc}{error}
18The exception raised on errors.
19\end{datadesc}
20
21\begin{datadesc}{cmData}
22\dataline{cmCntl}
23\dataline{cmAttn}
Fred Drake41788db1998-04-04 06:23:02 +000024Flags for the \var{channel} argument of the \method{Read()} and
25\method{Write()} methods.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000026\end{datadesc}
27
28\begin{datadesc}{cmFlagsEOM}
Fred Drake41788db1998-04-04 06:23:02 +000029End-of-message flag for \method{Read()} and \method{Write()}.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000030\end{datadesc}
31
32\begin{datadesc}{choose*}
Fred Drake41788db1998-04-04 06:23:02 +000033Values returned by \method{Choose()}.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000034\end{datadesc}
35
36\begin{datadesc}{cmStatus*}
Fred Drake41788db1998-04-04 06:23:02 +000037Bits in the status as returned by \method{Status()}.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000038\end{datadesc}
39
40\begin{funcdesc}{available}{}
Fred Drake41788db1998-04-04 06:23:02 +000041Return \code{1} if the Communication Toolbox is available, zero otherwise.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000042\end{funcdesc}
43
Fred Drakecce10901998-03-17 06:33:25 +000044\begin{funcdesc}{CMNew}{name, sizes}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000045Create a connection object using the connection tool named
46\var{name}. \var{sizes} is a 6-tuple given buffer sizes for data in,
47data out, control in, control out, attention in and attention out.
Fred Drake41788db1998-04-04 06:23:02 +000048Alternatively, passing \code{None} for \var{sizes} will result in
49default buffer sizes.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000050\end{funcdesc}
51
Fred Drakef6863c11999-03-02 16:37:17 +000052
53\subsection{Connection Objects \label{connection-object}}
Fred Drake41788db1998-04-04 06:23:02 +000054
Jack Jansendcb0a9b1995-03-01 14:05:27 +000055For all connection methods that take a \var{timeout} argument, a value
56of \code{-1} is indefinite, meaning that the command runs to completion.
57
Fred Drake41788db1998-04-04 06:23:02 +000058\begin{memberdesc}[connection]{callback}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000059If this member is set to a value other than \code{None} it should point
Jack Jansendcb0a9b1995-03-01 14:05:27 +000060to a function accepting a single argument (the connection
61object). This will make all connection object methods work
62asynchronously, with the callback routine being called upon
63completion.
64
Fred Drakeaf8a0151998-01-14 14:51:31 +000065\emph{Note:} for reasons beyond my understanding the callback routine
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000066is currently never called. You are advised against using asynchronous
Jack Jansendcb0a9b1995-03-01 14:05:27 +000067calls for the time being.
Fred Drake41788db1998-04-04 06:23:02 +000068\end{memberdesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000069
70
Fred Drake41788db1998-04-04 06:23:02 +000071\begin{methoddesc}[connection]{Open}{timeout}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000072Open an outgoing connection, waiting at most \var{timeout} seconds for
73the connection to be established.
Fred Drake41788db1998-04-04 06:23:02 +000074\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000075
Fred Drake41788db1998-04-04 06:23:02 +000076\begin{methoddesc}[connection]{Listen}{timeout}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000077Wait for an incoming connection. Stop waiting after \var{timeout}
78seconds. This call is only meaningful to some tools.
Fred Drake41788db1998-04-04 06:23:02 +000079\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000080
Fred Drake41788db1998-04-04 06:23:02 +000081\begin{methoddesc}[connection]{accept}{yesno}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000082Accept (when \var{yesno} is non-zero) or reject an incoming call after
Fred Drake41788db1998-04-04 06:23:02 +000083\method{Listen()} returned.
84\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000085
Fred Drake41788db1998-04-04 06:23:02 +000086\begin{methoddesc}[connection]{Close}{timeout, now}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000087Close a connection. When \var{now} is zero, the close is orderly
Fred Drake15e33d82001-07-06 06:49:32 +000088(outstanding output is flushed, etc.)\ with a timeout of
Jack Jansendcb0a9b1995-03-01 14:05:27 +000089\var{timeout} seconds. When \var{now} is non-zero the close is
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000090immediate, discarding output.
Fred Drake41788db1998-04-04 06:23:02 +000091\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000092
Fred Drake41788db1998-04-04 06:23:02 +000093\begin{methoddesc}[connection]{Read}{len, chan, timeout}
94Read \var{len} bytes, or until \var{timeout} seconds have passed, from
95the channel \var{chan} (which is one of \constant{cmData},
96\constant{cmCntl} or \constant{cmAttn}). Return a 2-tuple:\ the data
97read and the end-of-message flag, \constant{cmFlagsEOM}.
98\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000099
Fred Drake41788db1998-04-04 06:23:02 +0000100\begin{methoddesc}[connection]{Write}{buf, chan, timeout, eom}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000101Write \var{buf} to channel \var{chan}, aborting after \var{timeout}
Fred Drake41788db1998-04-04 06:23:02 +0000102seconds. When \var{eom} has the value \constant{cmFlagsEOM}, an
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000103end-of-message indicator will be written after the data (if this
104concept has a meaning for this communication tool). The method returns
105the number of bytes written.
Fred Drake41788db1998-04-04 06:23:02 +0000106\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000107
Fred Drake41788db1998-04-04 06:23:02 +0000108\begin{methoddesc}[connection]{Status}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000109Return connection status as the 2-tuple \code{(\var{sizes},
110\var{flags})}. \var{sizes} is a 6-tuple giving the actual buffer sizes used
Fred Drake41788db1998-04-04 06:23:02 +0000111(see \function{CMNew()}), \var{flags} is a set of bits describing the state
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000112of the connection.
Fred Drake41788db1998-04-04 06:23:02 +0000113\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000114
Fred Drake41788db1998-04-04 06:23:02 +0000115\begin{methoddesc}[connection]{GetConfig}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000116Return the configuration string of the communication tool. These
117configuration strings are tool-dependent, but usually easily parsed
118and modified.
Fred Drake41788db1998-04-04 06:23:02 +0000119\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000120
Fred Drake41788db1998-04-04 06:23:02 +0000121\begin{methoddesc}[connection]{SetConfig}{str}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000122Set the configuration string for the tool. The strings are parsed
123left-to-right, with later values taking precedence. This means
124individual configuration parameters can be modified by simply appending
125something like \code{'baud 4800'} to the end of the string returned by
Fred Drake41788db1998-04-04 06:23:02 +0000126\method{GetConfig()} and passing that to this method. The method returns
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000127the number of characters actually parsed by the tool before it
128encountered an error (or completed successfully).
Fred Drake41788db1998-04-04 06:23:02 +0000129\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000130
Fred Drake41788db1998-04-04 06:23:02 +0000131\begin{methoddesc}[connection]{Choose}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000132Present the user with a dialog to choose a communication tool and
133configure it. If there is an outstanding connection some choices (like
134selecting a different tool) may cause the connection to be
Fred Drake41788db1998-04-04 06:23:02 +0000135aborted. The return value (one of the \constant{choose*} constants) will
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000136indicate this.
Fred Drake41788db1998-04-04 06:23:02 +0000137\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000138
Fred Drake41788db1998-04-04 06:23:02 +0000139\begin{methoddesc}[connection]{Idle}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000140Give the tool a chance to use the processor. You should call this
141method regularly.
Fred Drake41788db1998-04-04 06:23:02 +0000142\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000143
Fred Drake41788db1998-04-04 06:23:02 +0000144\begin{methoddesc}[connection]{Abort}{}
145Abort an outstanding asynchronous \method{Open()} or \method{Listen()}.
146\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000147
Fred Drake41788db1998-04-04 06:23:02 +0000148\begin{methoddesc}[connection]{Reset}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000149Reset a connection. Exact meaning depends on the tool.
Fred Drake41788db1998-04-04 06:23:02 +0000150\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000151
Fred Drake41788db1998-04-04 06:23:02 +0000152\begin{methoddesc}[connection]{Break}{length}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000153Send a break. Whether this means anything, what it means and
Fred Drake41788db1998-04-04 06:23:02 +0000154interpretation of the \var{length} parameter depends on the tool in
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000155use.
Fred Drake41788db1998-04-04 06:23:02 +0000156\end{methoddesc}