cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 1 | #! python |
cliechti | c54b2c8 | 2008-06-21 01:59:08 +0000 | [diff] [blame] | 2 | # Python Serial Port Extension for Win32, Linux, BSD, Jython |
| 3 | # serial driver for win32 |
| 4 | # see __init__.py |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 5 | # |
Chris Liechti | 68340d7 | 2015-08-03 14:15:48 +0200 | [diff] [blame] | 6 | # (C) 2001-2015 Chris Liechti <cliechti@gmx.net> |
Chris Liechti | fbdd8a0 | 2015-08-09 02:37:45 +0200 | [diff] [blame] | 7 | # |
| 8 | # SPDX-License-Identifier: BSD-3-Clause |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 9 | # |
| 10 | # Initial patch to use ctypes by Giovanni Bajo <rasky@develer.com> |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 11 | |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 12 | import ctypes |
Chris Liechti | d240cf5 | 2015-08-05 02:57:03 +0200 | [diff] [blame] | 13 | import time |
cliechti | 39cfb7b | 2011-08-22 00:30:07 +0000 | [diff] [blame] | 14 | from serial import win32 |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 15 | |
cliechti | 39cfb7b | 2011-08-22 00:30:07 +0000 | [diff] [blame] | 16 | from serial.serialutil import * |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 17 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 18 | |
Chris Liechti | ef6b7b4 | 2015-08-06 22:19:26 +0200 | [diff] [blame] | 19 | class Serial(SerialBase): |
cliechti | 1e2a6df | 2009-07-24 02:00:50 +0000 | [diff] [blame] | 20 | """Serial port implementation for Win32 based on ctypes.""" |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 21 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 22 | BAUDRATES = (50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, |
| 23 | 9600, 19200, 38400, 57600, 115200) |
cliechti | 80a0ed1 | 2003-10-03 23:53:42 +0000 | [diff] [blame] | 24 | |
cliechti | 5735a07 | 2009-10-26 23:57:48 +0000 | [diff] [blame] | 25 | def __init__(self, *args, **kwargs): |
Chris Liechti | 76f8349 | 2015-08-10 01:22:01 +0200 | [diff] [blame] | 26 | super(SerialBase, self).__init__() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 27 | self._port_handle = None |
| 28 | self._overlapped_read = None |
| 29 | self._overlapped_write = None |
cliechti | 5735a07 | 2009-10-26 23:57:48 +0000 | [diff] [blame] | 30 | SerialBase.__init__(self, *args, **kwargs) |
| 31 | |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 32 | def open(self): |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 33 | """\ |
| 34 | Open port with current settings. This may throw a SerialException |
| 35 | if the port cannot be opened. |
| 36 | """ |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 37 | if self._port is None: |
| 38 | raise SerialException("Port must be configured before it can be used.") |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 39 | if self.is_open: |
cliechti | 8f69e70 | 2011-03-19 00:22:32 +0000 | [diff] [blame] | 40 | raise SerialException("Port is already open.") |
cliechti | 8b7cff0 | 2008-06-24 12:11:57 +0000 | [diff] [blame] | 41 | # the "\\.\COMx" format is required for devices other than COM1-COM8 |
| 42 | # not all versions of windows seem to support this properly |
| 43 | # so that the first few ports are used with the DOS device name |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 44 | port = self.name |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 45 | try: |
| 46 | if port.upper().startswith('COM') and int(port[3:]) > 8: |
| 47 | port = '\\\\.\\' + port |
| 48 | except ValueError: |
| 49 | # for like COMnotanumber |
| 50 | pass |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 51 | self._port_handle = win32.CreateFile(port, |
cliechti | e37b6a8 | 2009-07-24 12:19:50 +0000 | [diff] [blame] | 52 | win32.GENERIC_READ | win32.GENERIC_WRITE, |
| 53 | 0, # exclusive access |
| 54 | None, # no security |
| 55 | win32.OPEN_EXISTING, |
| 56 | win32.FILE_ATTRIBUTE_NORMAL | win32.FILE_FLAG_OVERLAPPED, |
| 57 | 0) |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 58 | if self._port_handle == win32.INVALID_HANDLE_VALUE: |
| 59 | self._port_handle = None # 'cause __del__ is called anyway |
cliechti | 1083be7 | 2011-12-28 20:45:30 +0000 | [diff] [blame] | 60 | raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.WinError())) |
cliechti | e37b6a8 | 2009-07-24 12:19:50 +0000 | [diff] [blame] | 61 | |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 62 | try: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 63 | self._overlapped_read = win32.OVERLAPPED() |
| 64 | self._overlapped_read.hEvent = win32.CreateEvent(None, 1, 0, None) |
| 65 | self._overlapped_write = win32.OVERLAPPED() |
| 66 | #~ self._overlapped_write.hEvent = win32.CreateEvent(None, 1, 0, None) |
| 67 | self._overlapped_write.hEvent = win32.CreateEvent(None, 0, 0, None) |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 68 | |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 69 | # Setup a 4k buffer |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 70 | win32.SetupComm(self._port_handle, 4096, 4096) |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 71 | |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 72 | # Save original timeout values: |
| 73 | self._orgTimeouts = win32.COMMTIMEOUTS() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 74 | win32.GetCommTimeouts(self._port_handle, ctypes.byref(self._orgTimeouts)) |
cliechti | edfba4e | 2009-02-07 00:29:47 +0000 | [diff] [blame] | 75 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 76 | self._reconfigure_port() |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 77 | |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 78 | # Clear buffers: |
| 79 | # Remove anything that was there |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 80 | win32.PurgeComm(self._port_handle, |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 81 | win32.PURGE_TXCLEAR | win32.PURGE_TXABORT | |
| 82 | win32.PURGE_RXCLEAR | win32.PURGE_RXABORT) |
| 83 | except: |
| 84 | try: |
| 85 | self._close() |
| 86 | except: |
| 87 | # ignore any exception when closing the port |
| 88 | # also to keep original exception that happened when setting up |
| 89 | pass |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 90 | self._port_handle = None |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 91 | raise |
| 92 | else: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 93 | self.is_open = True |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 94 | |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 95 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 96 | def _reconfigure_port(self): |
cliechti | cc8d9d2 | 2008-07-06 22:42:44 +0000 | [diff] [blame] | 97 | """Set communication parameters on opened port.""" |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 98 | if not self._port_handle: |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 99 | raise SerialException("Can only operate on a valid port handle") |
cliechti | edfba4e | 2009-02-07 00:29:47 +0000 | [diff] [blame] | 100 | |
| 101 | # Set Windows timeout values |
| 102 | # timeouts is a tuple with the following items: |
| 103 | # (ReadIntervalTimeout,ReadTotalTimeoutMultiplier, |
| 104 | # ReadTotalTimeoutConstant,WriteTotalTimeoutMultiplier, |
| 105 | # WriteTotalTimeoutConstant) |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 106 | if self._timeout is None: |
| 107 | timeouts = (0, 0, 0, 0, 0) |
| 108 | elif self._timeout == 0: |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 109 | timeouts = (win32.MAXDWORD, 0, 0, 0, 0) |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 110 | else: |
| 111 | timeouts = (0, 0, int(self._timeout*1000), 0, 0) |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 112 | if self._timeout != 0 and self._inter_character_timeout is not None: |
| 113 | timeouts = (int(self._inter_character_timeout * 1000),) + timeouts[1:] |
cliechti | edfba4e | 2009-02-07 00:29:47 +0000 | [diff] [blame] | 114 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 115 | if self._write_timeout is None: |
cliechti | 6261161 | 2004-04-20 01:55:43 +0000 | [diff] [blame] | 116 | pass |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 117 | elif self._write_timeout == 0: |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 118 | timeouts = timeouts[:-2] + (0, win32.MAXDWORD) |
cliechti | 6261161 | 2004-04-20 01:55:43 +0000 | [diff] [blame] | 119 | else: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 120 | timeouts = timeouts[:-2] + (0, int(self._write_timeout*1000)) |
| 121 | win32.SetCommTimeouts(self._port_handle, ctypes.byref(win32.COMMTIMEOUTS(*timeouts))) |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 122 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 123 | win32.SetCommMask(self._port_handle, win32.EV_ERR) |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 124 | |
cliechti | 95c6221 | 2002-03-04 22:17:53 +0000 | [diff] [blame] | 125 | # Setup the connection info. |
| 126 | # Get state and modify it: |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 127 | comDCB = win32.DCB() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 128 | win32.GetCommState(self._port_handle, ctypes.byref(comDCB)) |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 129 | comDCB.BaudRate = self._baudrate |
| 130 | |
| 131 | if self._bytesize == FIVEBITS: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 132 | comDCB.ByteSize = 5 |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 133 | elif self._bytesize == SIXBITS: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 134 | comDCB.ByteSize = 6 |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 135 | elif self._bytesize == SEVENBITS: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 136 | comDCB.ByteSize = 7 |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 137 | elif self._bytesize == EIGHTBITS: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 138 | comDCB.ByteSize = 8 |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 139 | else: |
| 140 | raise ValueError("Unsupported number of data bits: %r" % self._bytesize) |
| 141 | |
| 142 | if self._parity == PARITY_NONE: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 143 | comDCB.Parity = win32.NOPARITY |
| 144 | comDCB.fParity = 0 # Disable Parity Check |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 145 | elif self._parity == PARITY_EVEN: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 146 | comDCB.Parity = win32.EVENPARITY |
| 147 | comDCB.fParity = 1 # Enable Parity Check |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 148 | elif self._parity == PARITY_ODD: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 149 | comDCB.Parity = win32.ODDPARITY |
| 150 | comDCB.fParity = 1 # Enable Parity Check |
cliechti | c54b2c8 | 2008-06-21 01:59:08 +0000 | [diff] [blame] | 151 | elif self._parity == PARITY_MARK: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 152 | comDCB.Parity = win32.MARKPARITY |
| 153 | comDCB.fParity = 1 # Enable Parity Check |
cliechti | c54b2c8 | 2008-06-21 01:59:08 +0000 | [diff] [blame] | 154 | elif self._parity == PARITY_SPACE: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 155 | comDCB.Parity = win32.SPACEPARITY |
| 156 | comDCB.fParity = 1 # Enable Parity Check |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 157 | else: |
| 158 | raise ValueError("Unsupported parity mode: %r" % self._parity) |
| 159 | |
| 160 | if self._stopbits == STOPBITS_ONE: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 161 | comDCB.StopBits win32.ONESTOPBIT |
cliechti | 58b481c | 2009-02-16 20:42:32 +0000 | [diff] [blame] | 162 | elif self._stopbits == STOPBITS_ONE_POINT_FIVE: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 163 | comDCB.StopBits = win32.ONE5STOPBITS |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 164 | elif self._stopbits == STOPBITS_TWO: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 165 | comDCB.StopBits = win32.TWOSTOPBITS |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 166 | else: |
| 167 | raise ValueError("Unsupported number of stop bits: %r" % self._stopbits) |
cliechti | edfba4e | 2009-02-07 00:29:47 +0000 | [diff] [blame] | 168 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 169 | comDCB.fBinary = 1 # Enable Binary Transmission |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 170 | # Char. w/ Parity-Err are replaced with 0xff (if fErrorChar is set to TRUE) |
Chris Liechti | 33f0ec5 | 2015-08-06 16:37:21 +0200 | [diff] [blame] | 171 | if self._rs485_mode is None: |
| 172 | if self._rtscts: |
| 173 | comDCB.fRtsControl = win32.RTS_CONTROL_HANDSHAKE |
| 174 | else: |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 175 | comDCB.fRtsControl = win32.RTS_CONTROL_ENABLE if self._rts_state else win32.RTS_CONTROL_DISABLE |
Chris Liechti | 33f0ec5 | 2015-08-06 16:37:21 +0200 | [diff] [blame] | 176 | comDCB.fOutxCtsFlow = self._rtscts |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 177 | else: |
Chris Liechti | 33f0ec5 | 2015-08-06 16:37:21 +0200 | [diff] [blame] | 178 | # checks for unsupported settings |
| 179 | # XXX verify if platform really does not have a setting for those |
| 180 | if not self._rs485_mode.rts_level_for_tx: |
| 181 | raise ValueError( |
| 182 | 'Unsupported value for RS485Settings.rts_level_for_tx: %r' % ( |
| 183 | self._rs485_mode.rts_level_for_tx,)) |
| 184 | if self._rs485_mode.rts_level_for_rx: |
| 185 | raise ValueError( |
| 186 | 'Unsupported value for RS485Settings.rts_level_for_rx: %r' % ( |
| 187 | self._rs485_mode.rts_level_for_rx,)) |
| 188 | if self._rs485_mode.delay_before_tx is not None: |
| 189 | raise ValueError( |
| 190 | 'Unsupported value for RS485Settings.delay_before_tx: %r' % ( |
| 191 | self._rs485_mode.delay_before_tx,)) |
| 192 | if self._rs485_mode.delay_before_rx is not None: |
| 193 | raise ValueError( |
| 194 | 'Unsupported value for RS485Settings.delay_before_rx: %r' % ( |
| 195 | self._rs485_mode.delay_before_rx,)) |
| 196 | if self._rs485_mode.loopback: |
| 197 | raise ValueError( |
| 198 | 'Unsupported value for RS485Settings.loopback: %r' % ( |
| 199 | self._rs485_mode.loopback,)) |
| 200 | comDCB.fRtsControl = win32.RTS_CONTROL_TOGGLE |
| 201 | comDCB.fOutxCtsFlow = 0 |
| 202 | |
cliechti | f46e0a8 | 2005-05-19 15:24:57 +0000 | [diff] [blame] | 203 | if self._dsrdtr: |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 204 | comDCB.fDtrControl = win32.DTR_CONTROL_HANDSHAKE |
cliechti | f46e0a8 | 2005-05-19 15:24:57 +0000 | [diff] [blame] | 205 | else: |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 206 | comDCB.fDtrControl = win32.DTR_CONTROL_ENABLE if self._dtr_state else win32.DTR_CONTROL_DISABLE |
cliechti | f46e0a8 | 2005-05-19 15:24:57 +0000 | [diff] [blame] | 207 | comDCB.fOutxDsrFlow = self._dsrdtr |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 208 | comDCB.fOutX = self._xonxoff |
| 209 | comDCB.fInX = self._xonxoff |
| 210 | comDCB.fNull = 0 |
| 211 | comDCB.fErrorChar = 0 |
| 212 | comDCB.fAbortOnError = 0 |
cliechti | 6261161 | 2004-04-20 01:55:43 +0000 | [diff] [blame] | 213 | comDCB.XonChar = XON |
| 214 | comDCB.XoffChar = XOFF |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 215 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 216 | if not win32.SetCommState(self._port_handle, ctypes.byref(comDCB)): |
cliechti | 1083be7 | 2011-12-28 20:45:30 +0000 | [diff] [blame] | 217 | raise ValueError("Cannot configure port, some setting was wrong. Original message: %r" % ctypes.WinError()) |
cliechti | 95c6221 | 2002-03-04 22:17:53 +0000 | [diff] [blame] | 218 | |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 219 | #~ def __del__(self): |
| 220 | #~ self.close() |
| 221 | |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 222 | |
| 223 | def _close(self): |
| 224 | """internal close port helper""" |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 225 | if self._port_handle: |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 226 | # Restore original timeout values: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 227 | win32.SetCommTimeouts(self._port_handle, self._orgTimeouts) |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 228 | # Close COM-Port: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 229 | win32.CloseHandle(self._port_handle) |
| 230 | if self._overlapped_read is not None: |
| 231 | win32.CloseHandle(self._overlapped_read.hEvent) |
| 232 | self._overlapped_read = None |
| 233 | if self._overlapped_write is not None: |
| 234 | win32.CloseHandle(self._overlapped_write.hEvent) |
| 235 | self._overlapped_write = None |
| 236 | self._port_handle = None |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 237 | |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 238 | def close(self): |
| 239 | """Close port""" |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 240 | if self.is_open: |
cliechti | 1ae5ab0 | 2013-10-11 01:08:02 +0000 | [diff] [blame] | 241 | self._close() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 242 | self.is_open = False |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 243 | |
| 244 | # - - - - - - - - - - - - - - - - - - - - - - - - |
cliechti | edfba4e | 2009-02-07 00:29:47 +0000 | [diff] [blame] | 245 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 246 | @property |
| 247 | def in_waiting(self): |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 248 | """Return the number of bytes currently in the input buffer.""" |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 249 | flags = win32.DWORD() |
| 250 | comstat = win32.COMSTAT() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 251 | if not win32.ClearCommError(self._port_handle, ctypes.byref(flags), ctypes.byref(comstat)): |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 252 | raise SerialException('call to ClearCommError failed') |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 253 | return comstat.cbInQue |
| 254 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 255 | def read(self, size=1): |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 256 | """\ |
| 257 | Read size bytes from the serial port. If a timeout is set it may |
| 258 | return less characters as requested. With no timeout it will block |
| 259 | until the requested number of bytes is read.""" |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 260 | if not self._port_handle: raise portNotOpenError |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 261 | if size > 0: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 262 | win32.ResetEvent(self._overlapped_read.hEvent) |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 263 | flags = win32.DWORD() |
| 264 | comstat = win32.COMSTAT() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 265 | if not win32.ClearCommError(self._port_handle, ctypes.byref(flags), ctypes.byref(comstat)): |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 266 | raise SerialException('call to ClearCommError failed') |
cliechti | 5c39e70 | 2002-06-04 14:56:34 +0000 | [diff] [blame] | 267 | if self.timeout == 0: |
cliechti | 17f177f | 2002-06-07 22:33:37 +0000 | [diff] [blame] | 268 | n = min(comstat.cbInQue, size) |
| 269 | if n > 0: |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 270 | buf = ctypes.create_string_buffer(n) |
| 271 | rc = win32.DWORD() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 272 | err = win32.ReadFile(self._port_handle, buf, n, ctypes.byref(rc), ctypes.byref(self._overlapped_read)) |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 273 | if not err and win32.GetLastError() != win32.ERROR_IO_PENDING: |
cliechti | 1083be7 | 2011-12-28 20:45:30 +0000 | [diff] [blame] | 274 | raise SerialException("ReadFile failed (%r)" % ctypes.WinError()) |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 275 | err = win32.WaitForSingleObject(self._overlapped_read.hEvent, win32.INFINITE) |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 276 | read = buf.raw[:rc.value] |
cliechti | f622faf | 2003-07-12 23:41:43 +0000 | [diff] [blame] | 277 | else: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 278 | read = bytes() |
cliechti | 5c39e70 | 2002-06-04 14:56:34 +0000 | [diff] [blame] | 279 | else: |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 280 | buf = ctypes.create_string_buffer(size) |
| 281 | rc = win32.DWORD() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 282 | err = win32.ReadFile(self._port_handle, buf, size, ctypes.byref(rc), ctypes.byref(self._overlapped_read)) |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 283 | if not err and win32.GetLastError() != win32.ERROR_IO_PENDING: |
cliechti | 1083be7 | 2011-12-28 20:45:30 +0000 | [diff] [blame] | 284 | raise SerialException("ReadFile failed (%r)" % ctypes.WinError()) |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 285 | err = win32.GetOverlappedResult(self._port_handle, ctypes.byref(self._overlapped_read), ctypes.byref(rc), True) |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 286 | read = buf.raw[:rc.value] |
cliechti | f622faf | 2003-07-12 23:41:43 +0000 | [diff] [blame] | 287 | else: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 288 | read = bytes() |
| 289 | return bytes(read) |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 290 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 291 | def write(self, data): |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 292 | """Output the given byte string over the serial port.""" |
| 293 | if not self._port_handle: raise portNotOpenError |
cliechti | 23dc2a0 | 2009-07-30 17:25:09 +0000 | [diff] [blame] | 294 | #~ if not isinstance(data, (bytes, bytearray)): |
| 295 | #~ raise TypeError('expected %s or bytearray, got %s' % (bytes, type(data))) |
| 296 | # convert data (needed in case of memoryview instance: Py 3.1 io lib), ctypes doesn't like memoryview |
cliechti | 3807712 | 2013-10-16 02:57:27 +0000 | [diff] [blame] | 297 | data = to_bytes(data) |
cliechti | b2f5fc8 | 2006-10-20 00:09:07 +0000 | [diff] [blame] | 298 | if data: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 299 | #~ win32event.ResetEvent(self._overlapped_write.hEvent) |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 300 | n = win32.DWORD() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 301 | err = win32.WriteFile(self._port_handle, data, len(data), ctypes.byref(n), self._overlapped_write) |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 302 | if not err and win32.GetLastError() != win32.ERROR_IO_PENDING: |
cliechti | 1083be7 | 2011-12-28 20:45:30 +0000 | [diff] [blame] | 303 | raise SerialException("WriteFile failed (%r)" % ctypes.WinError()) |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 304 | if self._write_timeout != 0: # if blocking (None) or w/ write timeout (>0) |
cliechti | 31000fc | 2011-08-05 01:47:26 +0000 | [diff] [blame] | 305 | # Wait for the write to complete. |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 306 | #~ win32.WaitForSingleObject(self._overlapped_write.hEvent, win32.INFINITE) |
| 307 | err = win32.GetOverlappedResult(self._port_handle, self._overlapped_write, ctypes.byref(n), True) |
cliechti | 31000fc | 2011-08-05 01:47:26 +0000 | [diff] [blame] | 308 | if n.value != len(data): |
| 309 | raise writeTimeoutError |
cliechti | 23dc2a0 | 2009-07-30 17:25:09 +0000 | [diff] [blame] | 310 | return n.value |
| 311 | else: |
| 312 | return 0 |
cliechti | edfba4e | 2009-02-07 00:29:47 +0000 | [diff] [blame] | 313 | |
cliechti | 2640978 | 2013-05-31 00:47:16 +0000 | [diff] [blame] | 314 | def flush(self): |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 315 | """\ |
| 316 | Flush of file like objects. In this case, wait until all data |
| 317 | is written. |
| 318 | """ |
cliechti | 2640978 | 2013-05-31 00:47:16 +0000 | [diff] [blame] | 319 | while self.outWaiting(): |
| 320 | time.sleep(0.05) |
| 321 | # XXX could also use WaitCommEvent with mask EV_TXEMPTY, but it would |
| 322 | # require overlapped IO and its also only possible to set a single mask |
| 323 | # on the port--- |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 324 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 325 | def reset_input_buffer(self): |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 326 | """Clear input buffer, discarding all that is in the buffer.""" |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 327 | if not self._port_handle: raise portNotOpenError |
| 328 | win32.PurgeComm(self._port_handle, win32.PURGE_RXCLEAR | win32.PURGE_RXABORT) |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 329 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 330 | def reset_output_buffer(self): |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 331 | """\ |
| 332 | Clear output buffer, aborting the current output and discarding all |
| 333 | that is in the buffer. |
| 334 | """ |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 335 | if not self._port_handle: raise portNotOpenError |
| 336 | win32.PurgeComm(self._port_handle, win32.PURGE_TXCLEAR | win32.PURGE_TXABORT) |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 337 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 338 | def _update_break_state(self): |
cliechti | 997b63c | 2008-06-21 00:09:31 +0000 | [diff] [blame] | 339 | """Set break: Controls TXD. When active, to transmitting is possible.""" |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 340 | if not self._port_handle: raise portNotOpenError |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 341 | if self._break_state: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 342 | win32.SetCommBreak(self._port_handle) |
cliechti | 997b63c | 2008-06-21 00:09:31 +0000 | [diff] [blame] | 343 | else: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 344 | win32.ClearCommBreak(self._port_handle) |
cliechti | 997b63c | 2008-06-21 00:09:31 +0000 | [diff] [blame] | 345 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 346 | def _update_rts_state(self): |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 347 | """Set terminal status line: Request To Send""" |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 348 | if self._rts_state: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 349 | win32.EscapeCommFunction(self._port_handle, win32.SETRTS) |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 350 | else: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 351 | win32.EscapeCommFunction(self._port_handle, win32.CLRRTS) |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 352 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 353 | def _update_dtr_state(self): |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 354 | """Set terminal status line: Data Terminal Ready""" |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 355 | if self._dtr_state: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 356 | win32.EscapeCommFunction(self._port_handle, win32.SETDTR) |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 357 | else: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 358 | win32.EscapeCommFunction(self._port_handle, win32.CLRDTR) |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 359 | |
| 360 | def _GetCommModemStatus(self): |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 361 | if not self._port_handle: raise portNotOpenError |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 362 | stat = win32.DWORD() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 363 | win32.GetCommModemStatus(self._port_handle, ctypes.byref(stat)) |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 364 | return stat.value |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 365 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 366 | @property |
| 367 | def cts(self): |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 368 | """Read terminal status line: Clear To Send""" |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 369 | return win32.MS_CTS_ON & self._GetCommModemStatus() != 0 |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 370 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 371 | @property |
| 372 | def dsr(self): |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 373 | """Read terminal status line: Data Set Ready""" |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 374 | return win32.MS_DSR_ON & self._GetCommModemStatus() != 0 |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 375 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 376 | @property |
| 377 | def ri(self): |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 378 | """Read terminal status line: Ring Indicator""" |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 379 | return win32.MS_RING_ON & self._GetCommModemStatus() != 0 |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 380 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 381 | @property |
| 382 | def cd(self): |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 383 | """Read terminal status line: Carrier Detect""" |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 384 | return win32.MS_RLSD_ON & self._GetCommModemStatus() != 0 |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 385 | |
cliechti | a30a8a0 | 2003-10-05 12:28:13 +0000 | [diff] [blame] | 386 | # - - platform specific - - - - |
| 387 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 388 | def set_buffer_size(self, rx_size=4096, tx_size=None): |
cliechti | 5919964 | 2011-12-28 20:54:30 +0000 | [diff] [blame] | 389 | """\ |
| 390 | Recommend a buffer size to the driver (device driver can ignore this |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 391 | value). Must be called before the port is opended. |
cliechti | 5919964 | 2011-12-28 20:54:30 +0000 | [diff] [blame] | 392 | """ |
| 393 | if tx_size is None: tx_size = rx_size |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 394 | win32.SetupComm(self._port_handle, rx_size, tx_size) |
cliechti | 5919964 | 2011-12-28 20:54:30 +0000 | [diff] [blame] | 395 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 396 | def set_output_flow_control(self, level=True): |
cliechti | 2f0f8a3 | 2011-12-28 22:10:00 +0000 | [diff] [blame] | 397 | """\ |
| 398 | Manually control flow - when software flow control is enabled. |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 399 | This will do the same as if XON (true) or XOFF (false) are received |
| 400 | from the other device and control the transmission accordingly. |
cliechti | 2f0f8a3 | 2011-12-28 22:10:00 +0000 | [diff] [blame] | 401 | WARNING: this function is not portable to different platforms! |
| 402 | """ |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 403 | if not self._port_handle: raise portNotOpenError |
cliechti | a30a8a0 | 2003-10-05 12:28:13 +0000 | [diff] [blame] | 404 | if level: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 405 | win32.EscapeCommFunction(self._port_handle, win32.SETXON) |
cliechti | a30a8a0 | 2003-10-05 12:28:13 +0000 | [diff] [blame] | 406 | else: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 407 | win32.EscapeCommFunction(self._port_handle, win32.SETXOFF) |
cliechti | a30a8a0 | 2003-10-05 12:28:13 +0000 | [diff] [blame] | 408 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 409 | @property |
| 410 | def out_waiting(self): |
| 411 | """Return how many bytes the in the outgoing buffer""" |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 412 | flags = win32.DWORD() |
| 413 | comstat = win32.COMSTAT() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame] | 414 | if not win32.ClearCommError(self._port_handle, ctypes.byref(flags), ctypes.byref(comstat)): |
cliechti | 183d4ae | 2009-07-23 22:03:51 +0000 | [diff] [blame] | 415 | raise SerialException('call to ClearCommError failed') |
cliechti | c8e83d8 | 2009-07-21 21:34:05 +0000 | [diff] [blame] | 416 | return comstat.cbOutQue |
| 417 | |
cliechti | 1f89a0a | 2011-08-05 02:53:24 +0000 | [diff] [blame] | 418 | |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 419 | |
cliechti | edfba4e | 2009-02-07 00:29:47 +0000 | [diff] [blame] | 420 | # Nur Testfunktion!! |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 421 | if __name__ == '__main__': |
cliechti | 93db61b | 2006-08-26 19:16:18 +0000 | [diff] [blame] | 422 | s = Serial(0) |
cliechti | 7aaead3 | 2009-07-23 14:02:41 +0000 | [diff] [blame] | 423 | sys.stdout.write("%s\n" % s) |
cliechti | edfba4e | 2009-02-07 00:29:47 +0000 | [diff] [blame] | 424 | |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 425 | s = Serial() |
cliechti | 7aaead3 | 2009-07-23 14:02:41 +0000 | [diff] [blame] | 426 | sys.stdout.write("%s\n" % s) |
cliechti | edfba4e | 2009-02-07 00:29:47 +0000 | [diff] [blame] | 427 | |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 428 | s.baudrate = 19200 |
| 429 | s.databits = 7 |
| 430 | s.close() |
cliechti | 93db61b | 2006-08-26 19:16:18 +0000 | [diff] [blame] | 431 | s.port = 0 |
cliechti | d6bf52c | 2003-10-01 02:28:12 +0000 | [diff] [blame] | 432 | s.open() |
cliechti | 7aaead3 | 2009-07-23 14:02:41 +0000 | [diff] [blame] | 433 | sys.stdout.write("%s\n" % s) |
cliechti | 89b4af1 | 2002-02-12 23:24:41 +0000 | [diff] [blame] | 434 | |