blob: 59125d40db62a656a855ee2213fd7b3999d3735b [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{ctb}}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00002\declaremodule{builtin}{ctb}
3
4\modulesynopsis{Interfaces to the Communications Tool Box. Only the Connection
5Manager is currently supported.}
6
Jack Jansendcb0a9b1995-03-01 14:05:27 +00007
8This module provides a partial interface to the Macintosh
9Communications Toolbox. Currently, only Connection Manager tools are
Guido van Rossum96628a91995-04-10 11:34:00 +000010supported. It may not be available in all Mac Python versions.
Fred Drake41788db1998-04-04 06:23:02 +000011\index{Communications Toolbox, Macintosh}
12\index{Macintosh Communications Toolbox}
13\index{Connection Manager}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000014
15\begin{datadesc}{error}
16The exception raised on errors.
17\end{datadesc}
18
19\begin{datadesc}{cmData}
20\dataline{cmCntl}
21\dataline{cmAttn}
Fred Drake41788db1998-04-04 06:23:02 +000022Flags for the \var{channel} argument of the \method{Read()} and
23\method{Write()} methods.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000024\end{datadesc}
25
26\begin{datadesc}{cmFlagsEOM}
Fred Drake41788db1998-04-04 06:23:02 +000027End-of-message flag for \method{Read()} and \method{Write()}.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000028\end{datadesc}
29
30\begin{datadesc}{choose*}
Fred Drake41788db1998-04-04 06:23:02 +000031Values returned by \method{Choose()}.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000032\end{datadesc}
33
34\begin{datadesc}{cmStatus*}
Fred Drake41788db1998-04-04 06:23:02 +000035Bits in the status as returned by \method{Status()}.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000036\end{datadesc}
37
38\begin{funcdesc}{available}{}
Fred Drake41788db1998-04-04 06:23:02 +000039Return \code{1} if the Communication Toolbox is available, zero otherwise.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000040\end{funcdesc}
41
Fred Drakecce10901998-03-17 06:33:25 +000042\begin{funcdesc}{CMNew}{name, sizes}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000043Create a connection object using the connection tool named
44\var{name}. \var{sizes} is a 6-tuple given buffer sizes for data in,
45data out, control in, control out, attention in and attention out.
Fred Drake41788db1998-04-04 06:23:02 +000046Alternatively, passing \code{None} for \var{sizes} will result in
47default buffer sizes.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000048\end{funcdesc}
49
50\subsection{connection object}
Fred Drake41788db1998-04-04 06:23:02 +000051\label{connection-object}
52
Jack Jansendcb0a9b1995-03-01 14:05:27 +000053For all connection methods that take a \var{timeout} argument, a value
54of \code{-1} is indefinite, meaning that the command runs to completion.
55
Fred Drake41788db1998-04-04 06:23:02 +000056\begin{memberdesc}[connection]{callback}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000057If this member is set to a value other than \code{None} it should point
Jack Jansendcb0a9b1995-03-01 14:05:27 +000058to a function accepting a single argument (the connection
59object). This will make all connection object methods work
60asynchronously, with the callback routine being called upon
61completion.
62
Fred Drakeaf8a0151998-01-14 14:51:31 +000063\emph{Note:} for reasons beyond my understanding the callback routine
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000064is currently never called. You are advised against using asynchronous
Jack Jansendcb0a9b1995-03-01 14:05:27 +000065calls for the time being.
Fred Drake41788db1998-04-04 06:23:02 +000066\end{memberdesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000067
68
Fred Drake41788db1998-04-04 06:23:02 +000069\begin{methoddesc}[connection]{Open}{timeout}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000070Open an outgoing connection, waiting at most \var{timeout} seconds for
71the connection to be established.
Fred Drake41788db1998-04-04 06:23:02 +000072\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000073
Fred Drake41788db1998-04-04 06:23:02 +000074\begin{methoddesc}[connection]{Listen}{timeout}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000075Wait for an incoming connection. Stop waiting after \var{timeout}
76seconds. This call is only meaningful to some tools.
Fred Drake41788db1998-04-04 06:23:02 +000077\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000078
Fred Drake41788db1998-04-04 06:23:02 +000079\begin{methoddesc}[connection]{accept}{yesno}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000080Accept (when \var{yesno} is non-zero) or reject an incoming call after
Fred Drake41788db1998-04-04 06:23:02 +000081\method{Listen()} returned.
82\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000083
Fred Drake41788db1998-04-04 06:23:02 +000084\begin{methoddesc}[connection]{Close}{timeout, now}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000085Close a connection. When \var{now} is zero, the close is orderly
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000086(i.e.\ outstanding output is flushed, etc.)\ with a timeout of
Jack Jansendcb0a9b1995-03-01 14:05:27 +000087\var{timeout} seconds. When \var{now} is non-zero the close is
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000088immediate, discarding output.
Fred Drake41788db1998-04-04 06:23:02 +000089\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000090
Fred Drake41788db1998-04-04 06:23:02 +000091\begin{methoddesc}[connection]{Read}{len, chan, timeout}
92Read \var{len} bytes, or until \var{timeout} seconds have passed, from
93the channel \var{chan} (which is one of \constant{cmData},
94\constant{cmCntl} or \constant{cmAttn}). Return a 2-tuple:\ the data
95read and the end-of-message flag, \constant{cmFlagsEOM}.
96\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000097
Fred Drake41788db1998-04-04 06:23:02 +000098\begin{methoddesc}[connection]{Write}{buf, chan, timeout, eom}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000099Write \var{buf} to channel \var{chan}, aborting after \var{timeout}
Fred Drake41788db1998-04-04 06:23:02 +0000100seconds. When \var{eom} has the value \constant{cmFlagsEOM}, an
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000101end-of-message indicator will be written after the data (if this
102concept has a meaning for this communication tool). The method returns
103the number of bytes written.
Fred Drake41788db1998-04-04 06:23:02 +0000104\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000105
Fred Drake41788db1998-04-04 06:23:02 +0000106\begin{methoddesc}[connection]{Status}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000107Return connection status as the 2-tuple \code{(\var{sizes},
108\var{flags})}. \var{sizes} is a 6-tuple giving the actual buffer sizes used
Fred Drake41788db1998-04-04 06:23:02 +0000109(see \function{CMNew()}), \var{flags} is a set of bits describing the state
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000110of the connection.
Fred Drake41788db1998-04-04 06:23:02 +0000111\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000112
Fred Drake41788db1998-04-04 06:23:02 +0000113\begin{methoddesc}[connection]{GetConfig}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000114Return the configuration string of the communication tool. These
115configuration strings are tool-dependent, but usually easily parsed
116and modified.
Fred Drake41788db1998-04-04 06:23:02 +0000117\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000118
Fred Drake41788db1998-04-04 06:23:02 +0000119\begin{methoddesc}[connection]{SetConfig}{str}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000120Set the configuration string for the tool. The strings are parsed
121left-to-right, with later values taking precedence. This means
122individual configuration parameters can be modified by simply appending
123something like \code{'baud 4800'} to the end of the string returned by
Fred Drake41788db1998-04-04 06:23:02 +0000124\method{GetConfig()} and passing that to this method. The method returns
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000125the number of characters actually parsed by the tool before it
126encountered an error (or completed successfully).
Fred Drake41788db1998-04-04 06:23:02 +0000127\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000128
Fred Drake41788db1998-04-04 06:23:02 +0000129\begin{methoddesc}[connection]{Choose}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000130Present the user with a dialog to choose a communication tool and
131configure it. If there is an outstanding connection some choices (like
132selecting a different tool) may cause the connection to be
Fred Drake41788db1998-04-04 06:23:02 +0000133aborted. The return value (one of the \constant{choose*} constants) will
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000134indicate this.
Fred Drake41788db1998-04-04 06:23:02 +0000135\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000136
Fred Drake41788db1998-04-04 06:23:02 +0000137\begin{methoddesc}[connection]{Idle}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000138Give the tool a chance to use the processor. You should call this
139method regularly.
Fred Drake41788db1998-04-04 06:23:02 +0000140\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000141
Fred Drake41788db1998-04-04 06:23:02 +0000142\begin{methoddesc}[connection]{Abort}{}
143Abort an outstanding asynchronous \method{Open()} or \method{Listen()}.
144\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000145
Fred Drake41788db1998-04-04 06:23:02 +0000146\begin{methoddesc}[connection]{Reset}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000147Reset a connection. Exact meaning depends on the tool.
Fred Drake41788db1998-04-04 06:23:02 +0000148\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000149
Fred Drake41788db1998-04-04 06:23:02 +0000150\begin{methoddesc}[connection]{Break}{length}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000151Send a break. Whether this means anything, what it means and
Fred Drake41788db1998-04-04 06:23:02 +0000152interpretation of the \var{length} parameter depends on the tool in
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000153use.
Fred Drake41788db1998-04-04 06:23:02 +0000154\end{methoddesc}