Fred Drake | c817e27 | 1998-08-10 18:40:22 +0000 | [diff] [blame] | 1 | \section{\module{ctb} --- |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 2 | Interface to the Communications Tool Box} |
Fred Drake | fe7f3bc | 1998-07-23 17:55:31 +0000 | [diff] [blame] | 3 | |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 4 | \declaremodule{builtin}{ctb} |
| 5 | \platform{Mac} |
Fred Drake | f459a09 | 2000-10-14 04:49:36 +0000 | [diff] [blame] | 6 | \modulesynopsis{Interfaces to the Communications Tool Box. Only the |
| 7 | Connection Manager is supported.} |
Fred Drake | fe7f3bc | 1998-07-23 17:55:31 +0000 | [diff] [blame] | 8 | |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 9 | |
| 10 | This module provides a partial interface to the Macintosh |
| 11 | Communications Toolbox. Currently, only Connection Manager tools are |
Jack Jansen | 827713a | 2001-09-11 20:18:04 +0000 | [diff] [blame] | 12 | supported. |
| 13 | |
| 14 | This module is only available under MacOS9 or earlier, in classic PPC |
| 15 | MacPython. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 16 | \index{Communications Toolbox, Macintosh} |
| 17 | \index{Macintosh Communications Toolbox} |
| 18 | \index{Connection Manager} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 19 | |
| 20 | \begin{datadesc}{error} |
| 21 | The exception raised on errors. |
| 22 | \end{datadesc} |
| 23 | |
| 24 | \begin{datadesc}{cmData} |
| 25 | \dataline{cmCntl} |
| 26 | \dataline{cmAttn} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 27 | Flags for the \var{channel} argument of the \method{Read()} and |
| 28 | \method{Write()} methods. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 29 | \end{datadesc} |
| 30 | |
| 31 | \begin{datadesc}{cmFlagsEOM} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 32 | End-of-message flag for \method{Read()} and \method{Write()}. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 33 | \end{datadesc} |
| 34 | |
| 35 | \begin{datadesc}{choose*} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 36 | Values returned by \method{Choose()}. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 37 | \end{datadesc} |
| 38 | |
| 39 | \begin{datadesc}{cmStatus*} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 40 | Bits in the status as returned by \method{Status()}. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 41 | \end{datadesc} |
| 42 | |
| 43 | \begin{funcdesc}{available}{} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 44 | Return \code{1} if the Communication Toolbox is available, zero otherwise. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 45 | \end{funcdesc} |
| 46 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 47 | \begin{funcdesc}{CMNew}{name, sizes} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 48 | Create a connection object using the connection tool named |
| 49 | \var{name}. \var{sizes} is a 6-tuple given buffer sizes for data in, |
| 50 | data out, control in, control out, attention in and attention out. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 51 | Alternatively, passing \code{None} for \var{sizes} will result in |
| 52 | default buffer sizes. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 53 | \end{funcdesc} |
| 54 | |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 55 | |
| 56 | \subsection{Connection Objects \label{connection-object}} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 57 | |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 58 | For all connection methods that take a \var{timeout} argument, a value |
| 59 | of \code{-1} is indefinite, meaning that the command runs to completion. |
| 60 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 61 | \begin{memberdesc}[connection]{callback} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 62 | If this member is set to a value other than \code{None} it should point |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 63 | to a function accepting a single argument (the connection |
| 64 | object). This will make all connection object methods work |
| 65 | asynchronously, with the callback routine being called upon |
| 66 | completion. |
| 67 | |
Fred Drake | 0aa811c | 2001-10-20 04:24:09 +0000 | [diff] [blame] | 68 | \note{For reasons beyond my understanding, the callback routine |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 69 | is currently never called. You are advised against using asynchronous |
Fred Drake | 0aa811c | 2001-10-20 04:24:09 +0000 | [diff] [blame] | 70 | calls for the time being.} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 71 | \end{memberdesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 72 | |
| 73 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 74 | \begin{methoddesc}[connection]{Open}{timeout} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 75 | Open an outgoing connection, waiting at most \var{timeout} seconds for |
| 76 | the connection to be established. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 77 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 78 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 79 | \begin{methoddesc}[connection]{Listen}{timeout} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 80 | Wait for an incoming connection. Stop waiting after \var{timeout} |
| 81 | seconds. This call is only meaningful to some tools. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 82 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 83 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 84 | \begin{methoddesc}[connection]{accept}{yesno} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 85 | Accept (when \var{yesno} is non-zero) or reject an incoming call after |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 86 | \method{Listen()} returned. |
| 87 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 88 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 89 | \begin{methoddesc}[connection]{Close}{timeout, now} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 90 | Close a connection. When \var{now} is zero, the close is orderly |
Fred Drake | 15e33d8 | 2001-07-06 06:49:32 +0000 | [diff] [blame] | 91 | (outstanding output is flushed, etc.)\ with a timeout of |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 92 | \var{timeout} seconds. When \var{now} is non-zero the close is |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 93 | immediate, discarding output. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 94 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 95 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 96 | \begin{methoddesc}[connection]{Read}{len, chan, timeout} |
| 97 | Read \var{len} bytes, or until \var{timeout} seconds have passed, from |
| 98 | the channel \var{chan} (which is one of \constant{cmData}, |
| 99 | \constant{cmCntl} or \constant{cmAttn}). Return a 2-tuple:\ the data |
| 100 | read and the end-of-message flag, \constant{cmFlagsEOM}. |
| 101 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 102 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 103 | \begin{methoddesc}[connection]{Write}{buf, chan, timeout, eom} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 104 | Write \var{buf} to channel \var{chan}, aborting after \var{timeout} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 105 | seconds. When \var{eom} has the value \constant{cmFlagsEOM}, an |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 106 | end-of-message indicator will be written after the data (if this |
| 107 | concept has a meaning for this communication tool). The method returns |
| 108 | the number of bytes written. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 109 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 110 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 111 | \begin{methoddesc}[connection]{Status}{} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 112 | Return connection status as the 2-tuple \code{(\var{sizes}, |
| 113 | \var{flags})}. \var{sizes} is a 6-tuple giving the actual buffer sizes used |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 114 | (see \function{CMNew()}), \var{flags} is a set of bits describing the state |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 115 | of the connection. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 116 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 117 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 118 | \begin{methoddesc}[connection]{GetConfig}{} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 119 | Return the configuration string of the communication tool. These |
| 120 | configuration strings are tool-dependent, but usually easily parsed |
| 121 | and modified. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 122 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 123 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 124 | \begin{methoddesc}[connection]{SetConfig}{str} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 125 | Set the configuration string for the tool. The strings are parsed |
| 126 | left-to-right, with later values taking precedence. This means |
| 127 | individual configuration parameters can be modified by simply appending |
| 128 | something like \code{'baud 4800'} to the end of the string returned by |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 129 | \method{GetConfig()} and passing that to this method. The method returns |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 130 | the number of characters actually parsed by the tool before it |
| 131 | encountered an error (or completed successfully). |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 132 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 133 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 134 | \begin{methoddesc}[connection]{Choose}{} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 135 | Present the user with a dialog to choose a communication tool and |
| 136 | configure it. If there is an outstanding connection some choices (like |
| 137 | selecting a different tool) may cause the connection to be |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 138 | aborted. The return value (one of the \constant{choose*} constants) will |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 139 | indicate this. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 140 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 141 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 142 | \begin{methoddesc}[connection]{Idle}{} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 143 | Give the tool a chance to use the processor. You should call this |
| 144 | method regularly. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 145 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 146 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 147 | \begin{methoddesc}[connection]{Abort}{} |
| 148 | Abort an outstanding asynchronous \method{Open()} or \method{Listen()}. |
| 149 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 150 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 151 | \begin{methoddesc}[connection]{Reset}{} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 152 | Reset a connection. Exact meaning depends on the tool. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 153 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 154 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 155 | \begin{methoddesc}[connection]{Break}{length} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 156 | Send a break. Whether this means anything, what it means and |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 157 | interpretation of the \var{length} parameter depends on the tool in |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 158 | use. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 159 | \end{methoddesc} |