blob: d7302be4e25ad299d68a0e9ed4704c2222ba3b71 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{ctb}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-ctb}
Jack Jansendcb0a9b1995-03-01 14:05:27 +00003\bimodindex{ctb}
Jack Jansendcb0a9b1995-03-01 14:05:27 +00004
5This module provides a partial interface to the Macintosh
6Communications Toolbox. Currently, only Connection Manager tools are
Guido van Rossum96628a91995-04-10 11:34:00 +00007supported. It may not be available in all Mac Python versions.
Fred Drake41788db1998-04-04 06:23:02 +00008\index{Communications Toolbox, Macintosh}
9\index{Macintosh Communications Toolbox}
10\index{Connection Manager}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000011
12\begin{datadesc}{error}
13The exception raised on errors.
14\end{datadesc}
15
16\begin{datadesc}{cmData}
17\dataline{cmCntl}
18\dataline{cmAttn}
Fred Drake41788db1998-04-04 06:23:02 +000019Flags for the \var{channel} argument of the \method{Read()} and
20\method{Write()} methods.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000021\end{datadesc}
22
23\begin{datadesc}{cmFlagsEOM}
Fred Drake41788db1998-04-04 06:23:02 +000024End-of-message flag for \method{Read()} and \method{Write()}.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000025\end{datadesc}
26
27\begin{datadesc}{choose*}
Fred Drake41788db1998-04-04 06:23:02 +000028Values returned by \method{Choose()}.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000029\end{datadesc}
30
31\begin{datadesc}{cmStatus*}
Fred Drake41788db1998-04-04 06:23:02 +000032Bits in the status as returned by \method{Status()}.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000033\end{datadesc}
34
35\begin{funcdesc}{available}{}
Fred Drake41788db1998-04-04 06:23:02 +000036Return \code{1} if the Communication Toolbox is available, zero otherwise.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000037\end{funcdesc}
38
Fred Drakecce10901998-03-17 06:33:25 +000039\begin{funcdesc}{CMNew}{name, sizes}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000040Create a connection object using the connection tool named
41\var{name}. \var{sizes} is a 6-tuple given buffer sizes for data in,
42data out, control in, control out, attention in and attention out.
Fred Drake41788db1998-04-04 06:23:02 +000043Alternatively, passing \code{None} for \var{sizes} will result in
44default buffer sizes.
Jack Jansendcb0a9b1995-03-01 14:05:27 +000045\end{funcdesc}
46
47\subsection{connection object}
Fred Drake41788db1998-04-04 06:23:02 +000048\label{connection-object}
49
Jack Jansendcb0a9b1995-03-01 14:05:27 +000050For all connection methods that take a \var{timeout} argument, a value
51of \code{-1} is indefinite, meaning that the command runs to completion.
52
Fred Drake41788db1998-04-04 06:23:02 +000053\begin{memberdesc}[connection]{callback}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000054If this member is set to a value other than \code{None} it should point
Jack Jansendcb0a9b1995-03-01 14:05:27 +000055to a function accepting a single argument (the connection
56object). This will make all connection object methods work
57asynchronously, with the callback routine being called upon
58completion.
59
Fred Drakeaf8a0151998-01-14 14:51:31 +000060\emph{Note:} for reasons beyond my understanding the callback routine
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000061is currently never called. You are advised against using asynchronous
Jack Jansendcb0a9b1995-03-01 14:05:27 +000062calls for the time being.
Fred Drake41788db1998-04-04 06:23:02 +000063\end{memberdesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000064
65
Fred Drake41788db1998-04-04 06:23:02 +000066\begin{methoddesc}[connection]{Open}{timeout}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000067Open an outgoing connection, waiting at most \var{timeout} seconds for
68the connection to be established.
Fred Drake41788db1998-04-04 06:23:02 +000069\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000070
Fred Drake41788db1998-04-04 06:23:02 +000071\begin{methoddesc}[connection]{Listen}{timeout}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000072Wait for an incoming connection. Stop waiting after \var{timeout}
73seconds. This call is only meaningful to some tools.
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]{accept}{yesno}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000077Accept (when \var{yesno} is non-zero) or reject an incoming call after
Fred Drake41788db1998-04-04 06:23:02 +000078\method{Listen()} returned.
79\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000080
Fred Drake41788db1998-04-04 06:23:02 +000081\begin{methoddesc}[connection]{Close}{timeout, now}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000082Close a connection. When \var{now} is zero, the close is orderly
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000083(i.e.\ outstanding output is flushed, etc.)\ with a timeout of
Jack Jansendcb0a9b1995-03-01 14:05:27 +000084\var{timeout} seconds. When \var{now} is non-zero the close is
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000085immediate, discarding output.
Fred Drake41788db1998-04-04 06:23:02 +000086\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000087
Fred Drake41788db1998-04-04 06:23:02 +000088\begin{methoddesc}[connection]{Read}{len, chan, timeout}
89Read \var{len} bytes, or until \var{timeout} seconds have passed, from
90the channel \var{chan} (which is one of \constant{cmData},
91\constant{cmCntl} or \constant{cmAttn}). Return a 2-tuple:\ the data
92read and the end-of-message flag, \constant{cmFlagsEOM}.
93\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000094
Fred Drake41788db1998-04-04 06:23:02 +000095\begin{methoddesc}[connection]{Write}{buf, chan, timeout, eom}
Jack Jansendcb0a9b1995-03-01 14:05:27 +000096Write \var{buf} to channel \var{chan}, aborting after \var{timeout}
Fred Drake41788db1998-04-04 06:23:02 +000097seconds. When \var{eom} has the value \constant{cmFlagsEOM}, an
Jack Jansendcb0a9b1995-03-01 14:05:27 +000098end-of-message indicator will be written after the data (if this
99concept has a meaning for this communication tool). The method returns
100the number of bytes written.
Fred Drake41788db1998-04-04 06:23:02 +0000101\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000102
Fred Drake41788db1998-04-04 06:23:02 +0000103\begin{methoddesc}[connection]{Status}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000104Return connection status as the 2-tuple \code{(\var{sizes},
105\var{flags})}. \var{sizes} is a 6-tuple giving the actual buffer sizes used
Fred Drake41788db1998-04-04 06:23:02 +0000106(see \function{CMNew()}), \var{flags} is a set of bits describing the state
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000107of the connection.
Fred Drake41788db1998-04-04 06:23:02 +0000108\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000109
Fred Drake41788db1998-04-04 06:23:02 +0000110\begin{methoddesc}[connection]{GetConfig}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000111Return the configuration string of the communication tool. These
112configuration strings are tool-dependent, but usually easily parsed
113and modified.
Fred Drake41788db1998-04-04 06:23:02 +0000114\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000115
Fred Drake41788db1998-04-04 06:23:02 +0000116\begin{methoddesc}[connection]{SetConfig}{str}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000117Set the configuration string for the tool. The strings are parsed
118left-to-right, with later values taking precedence. This means
119individual configuration parameters can be modified by simply appending
120something like \code{'baud 4800'} to the end of the string returned by
Fred Drake41788db1998-04-04 06:23:02 +0000121\method{GetConfig()} and passing that to this method. The method returns
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000122the number of characters actually parsed by the tool before it
123encountered an error (or completed successfully).
Fred Drake41788db1998-04-04 06:23:02 +0000124\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000125
Fred Drake41788db1998-04-04 06:23:02 +0000126\begin{methoddesc}[connection]{Choose}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000127Present the user with a dialog to choose a communication tool and
128configure it. If there is an outstanding connection some choices (like
129selecting a different tool) may cause the connection to be
Fred Drake41788db1998-04-04 06:23:02 +0000130aborted. The return value (one of the \constant{choose*} constants) will
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000131indicate this.
Fred Drake41788db1998-04-04 06:23:02 +0000132\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000133
Fred Drake41788db1998-04-04 06:23:02 +0000134\begin{methoddesc}[connection]{Idle}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000135Give the tool a chance to use the processor. You should call this
136method regularly.
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]{Abort}{}
140Abort an outstanding asynchronous \method{Open()} or \method{Listen()}.
141\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000142
Fred Drake41788db1998-04-04 06:23:02 +0000143\begin{methoddesc}[connection]{Reset}{}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000144Reset a connection. Exact meaning depends on the tool.
Fred Drake41788db1998-04-04 06:23:02 +0000145\end{methoddesc}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000146
Fred Drake41788db1998-04-04 06:23:02 +0000147\begin{methoddesc}[connection]{Break}{length}
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000148Send a break. Whether this means anything, what it means and
Fred Drake41788db1998-04-04 06:23:02 +0000149interpretation of the \var{length} parameter depends on the tool in
Jack Jansendcb0a9b1995-03-01 14:05:27 +0000150use.
Fred Drake41788db1998-04-04 06:23:02 +0000151\end{methoddesc}