cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 1 | #! python |
| 2 | # |
| 3 | # Python Serial Port Extension for Win32, Linux, BSD, Jython |
| 4 | # see __init__.py |
| 5 | # |
| 6 | # This module implements a loop back connection receiving itself what it sent. |
| 7 | # |
| 8 | # The purpose of this module is.. well... You can run the unit tests with it. |
| 9 | # and it was so easy to implement ;-) |
| 10 | # |
Chris Liechti | c4bca9e | 2015-08-07 14:40:41 +0200 | [diff] [blame] | 11 | # (C) 2001-2015 Chris Liechti <cliechti@gmx.net> |
Chris Liechti | fbdd8a0 | 2015-08-09 02:37:45 +0200 | [diff] [blame] | 12 | # |
| 13 | # SPDX-License-Identifier: BSD-3-Clause |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 14 | # |
| 15 | # URL format: loop://[option[/option...]] |
| 16 | # options: |
| 17 | # - "debug" print diagnostic messages |
Chris Liechti | c4bca9e | 2015-08-07 14:40:41 +0200 | [diff] [blame] | 18 | import logging |
| 19 | import numbers |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 20 | import threading |
| 21 | import time |
Chris Liechti | c4bca9e | 2015-08-07 14:40:41 +0200 | [diff] [blame] | 22 | try: |
| 23 | import urlparse |
| 24 | except ImportError: |
| 25 | import urllib.parse as urlparse |
Chris Liechti | a469cde | 2015-08-11 23:05:24 +0200 | [diff] [blame] | 26 | try: |
| 27 | import queue |
| 28 | except ImportError: |
| 29 | import Queue as queue |
Chris Liechti | c4bca9e | 2015-08-07 14:40:41 +0200 | [diff] [blame] | 30 | |
| 31 | from serial.serialutil import * |
cliechti | c64ba69 | 2009-08-12 00:32:47 +0000 | [diff] [blame] | 32 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 33 | # map log level names to constants. used in from_url() |
cliechti | c64ba69 | 2009-08-12 00:32:47 +0000 | [diff] [blame] | 34 | LOGGER_LEVELS = { |
Chris Liechti | c4bca9e | 2015-08-07 14:40:41 +0200 | [diff] [blame] | 35 | 'debug': logging.DEBUG, |
| 36 | 'info': logging.INFO, |
| 37 | 'warning': logging.WARNING, |
| 38 | 'error': logging.ERROR, |
| 39 | } |
cliechti | c64ba69 | 2009-08-12 00:32:47 +0000 | [diff] [blame] | 40 | |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 41 | |
Chris Liechti | ef6b7b4 | 2015-08-06 22:19:26 +0200 | [diff] [blame] | 42 | class Serial(SerialBase): |
cliechti | ab3d428 | 2011-08-19 01:52:46 +0000 | [diff] [blame] | 43 | """Serial port implementation that simulates a loop back connection in plain software.""" |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 44 | |
| 45 | BAUDRATES = (50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, |
| 46 | 9600, 19200, 38400, 57600, 115200) |
| 47 | |
Chris Liechti | a469cde | 2015-08-11 23:05:24 +0200 | [diff] [blame] | 48 | def __init__(self, *args, **kwargs): |
| 49 | super(Serial, self).__init__(*args, **kwargs) |
| 50 | self.buffer_size = 4096 |
| 51 | |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 52 | def open(self): |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 53 | """\ |
| 54 | Open port with current settings. This may throw a SerialException |
| 55 | if the port cannot be opened. |
| 56 | """ |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 57 | if self.is_open: |
cliechti | 8f69e70 | 2011-03-19 00:22:32 +0000 | [diff] [blame] | 58 | raise SerialException("Port is already open.") |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 59 | self.logger = None |
Chris Liechti | a469cde | 2015-08-11 23:05:24 +0200 | [diff] [blame] | 60 | self.queue = queue.Queue(self.buffer_size) |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 61 | |
| 62 | if self._port is None: |
| 63 | raise SerialException("Port must be configured before it can be used.") |
| 64 | # not that there is anything to open, but the function applies the |
| 65 | # options found in the URL |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 66 | self.from_url(self.port) |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 67 | |
| 68 | # not that there anything to configure... |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 69 | self._reconfigure_port() |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 70 | # all things set up get, now a clean start |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 71 | self.is_open = True |
| 72 | if not self._dsrdtr: |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 73 | self._update_dtr_state() |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 74 | if not self._rtscts: |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 75 | self._update_rts_state() |
| 76 | self.reset_input_buffer() |
| 77 | self.reset_output_buffer() |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 78 | |
Chris Liechti | a469cde | 2015-08-11 23:05:24 +0200 | [diff] [blame] | 79 | def close(self): |
| 80 | self.queue.put(None) |
| 81 | super(Serial, self).close() |
| 82 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 83 | def _reconfigure_port(self): |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 84 | """\ |
| 85 | Set communication parameters on opened port. For the loop:// |
| 86 | protocol all settings are ignored! |
| 87 | """ |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 88 | # not that's it of any real use, but it helps in the unit tests |
Chris Liechti | c4bca9e | 2015-08-07 14:40:41 +0200 | [diff] [blame] | 89 | if not isinstance(self._baudrate, numbers.Integral) or not 0 < self._baudrate < 2**32: |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 90 | raise ValueError("invalid baudrate: %r" % (self._baudrate)) |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 91 | if self.logger: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 92 | self.logger.info('_reconfigure_port()') |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 93 | |
| 94 | def close(self): |
| 95 | """Close port""" |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 96 | if self.is_open: |
| 97 | self.is_open = False |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 98 | # in case of quick reconnects, give the server some time |
| 99 | time.sleep(0.3) |
| 100 | |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 101 | def from_url(self, url): |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 102 | """extract host and port from an URL string""" |
Chris Liechti | c4bca9e | 2015-08-07 14:40:41 +0200 | [diff] [blame] | 103 | parts = urlparse.urlsplit(url) |
Chris Liechti | d14b1ab | 2015-08-21 00:28:53 +0200 | [diff] [blame] | 104 | if parts.scheme != "loop": |
| 105 | raise SerialException('expected a string in the form "loop://[?logging={debug|info|warning|error}]": not starting with loop:// (%r)' % (parts.scheme,)) |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 106 | try: |
| 107 | # process options now, directly altering self |
Chris Liechti | d14b1ab | 2015-08-21 00:28:53 +0200 | [diff] [blame] | 108 | for option, values in urlparse.parse_qs(parts.query, True).items(): |
| 109 | if option == 'logging': |
cliechti | c64ba69 | 2009-08-12 00:32:47 +0000 | [diff] [blame] | 110 | logging.basicConfig() # XXX is that good to call it here? |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 111 | self.logger = logging.getLogger('pySerial.loop') |
Chris Liechti | d14b1ab | 2015-08-21 00:28:53 +0200 | [diff] [blame] | 112 | self.logger.setLevel(LOGGER_LEVELS[values[0]]) |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 113 | self.logger.debug('enabled logging') |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 114 | else: |
| 115 | raise ValueError('unknown option: %r' % (option,)) |
Chris Liechti | 68340d7 | 2015-08-03 14:15:48 +0200 | [diff] [blame] | 116 | except ValueError as e: |
Chris Liechti | d14b1ab | 2015-08-21 00:28:53 +0200 | [diff] [blame] | 117 | raise SerialException('expected a string in the form "loop://[?logging={debug|info|warning|error}]": %s' % e) |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 118 | |
| 119 | # - - - - - - - - - - - - - - - - - - - - - - - - |
| 120 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 121 | @property |
| 122 | def in_waiting(self): |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 123 | """Return the number of bytes currently in the input buffer.""" |
| 124 | if not self.is_open: raise portNotOpenError |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 125 | if self.logger: |
cliechti | c64ba69 | 2009-08-12 00:32:47 +0000 | [diff] [blame] | 126 | # attention the logged value can differ from return value in |
| 127 | # threaded environments... |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 128 | self.logger.debug('in_waiting -> %d' % (self.queue.qsize(),)) |
Chris Liechti | a469cde | 2015-08-11 23:05:24 +0200 | [diff] [blame] | 129 | return self.queue.qsize() |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 130 | |
| 131 | def read(self, size=1): |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 132 | """\ |
| 133 | Read size bytes from the serial port. If a timeout is set it may |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 134 | return less characters as requested. With no timeout it will block |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 135 | until the requested number of bytes is read. |
| 136 | """ |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 137 | if not self.is_open: raise portNotOpenError |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 138 | if self._timeout is not None: |
| 139 | timeout = time.time() + self._timeout |
| 140 | else: |
cliechti | 024b4f4 | 2009-08-07 18:43:05 +0000 | [diff] [blame] | 141 | timeout = None |
cliechti | 1de32cd | 2009-08-07 19:05:09 +0000 | [diff] [blame] | 142 | data = bytearray() |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 143 | while size > 0 and self.is_open: |
Chris Liechti | a469cde | 2015-08-11 23:05:24 +0200 | [diff] [blame] | 144 | try: |
| 145 | data += self.queue.get(timeout=self._timeout) # XXX inter char timeout |
| 146 | except queue.Empty: |
| 147 | break |
| 148 | else: |
| 149 | size -= 1 |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 150 | # check for timeout now, after data has been read. |
| 151 | # useful for timeout = 0 (non blocking) read |
cliechti | 024b4f4 | 2009-08-07 18:43:05 +0000 | [diff] [blame] | 152 | if timeout and time.time() > timeout: |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 153 | break |
| 154 | return bytes(data) |
| 155 | |
| 156 | def write(self, data): |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 157 | """\ |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 158 | Output the given byte string over the serial port. Can block if the |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 159 | connection is blocked. May raise SerialException if the connection is |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 160 | closed. |
| 161 | """ |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 162 | if not self.is_open: raise portNotOpenError |
cliechti | 3807712 | 2013-10-16 02:57:27 +0000 | [diff] [blame] | 163 | data = to_bytes(data) |
cliechti | 66957bf | 2009-08-06 23:25:37 +0000 | [diff] [blame] | 164 | # calculate aprox time that would be used to send the data |
| 165 | time_used_to_send = 10.0*len(data) / self._baudrate |
| 166 | # when a write timeout is configured check if we would be successful |
| 167 | # (not sending anything, not even the part that would have time) |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 168 | if self._write_timeout is not None and time_used_to_send > self._write_timeout: |
| 169 | time.sleep(self._write_timeout) # must wait so that unit test succeeds |
cliechti | 66957bf | 2009-08-06 23:25:37 +0000 | [diff] [blame] | 170 | raise writeTimeoutError |
Chris Liechti | f99cd5c | 2015-08-13 22:54:16 +0200 | [diff] [blame] | 171 | for byte in iterbytes(data): |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 172 | self.queue.put(byte, timeout=self._write_timeout) |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 173 | return len(data) |
| 174 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 175 | def reset_input_buffer(self): |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 176 | """Clear input buffer, discarding all that is in the buffer.""" |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 177 | if not self.is_open: raise portNotOpenError |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 178 | if self.logger: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 179 | self.logger.info('reset_input_buffer()') |
Chris Liechti | a469cde | 2015-08-11 23:05:24 +0200 | [diff] [blame] | 180 | try: |
| 181 | while self.queue.qsize(): |
| 182 | self.queue.get_nowait() |
| 183 | except queue.Empty: |
| 184 | pass |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 185 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 186 | def reset_output_buffer(self): |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 187 | """\ |
| 188 | Clear output buffer, aborting the current output and |
| 189 | discarding all that is in the buffer. |
| 190 | """ |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 191 | if not self.is_open: raise portNotOpenError |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 192 | if self.logger: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 193 | self.logger.info('reset_output_buffer()') |
Chris Liechti | a469cde | 2015-08-11 23:05:24 +0200 | [diff] [blame] | 194 | try: |
| 195 | while self.queue.qsize(): |
| 196 | self.queue.get_nowait() |
| 197 | except queue.Empty: |
| 198 | pass |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 199 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 200 | def _update_break_state(self): |
cliechti | 7d44856 | 2014-08-03 21:57:45 +0000 | [diff] [blame] | 201 | """\ |
| 202 | Set break: Controls TXD. When active, to transmitting is |
| 203 | possible. |
| 204 | """ |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 205 | if self.logger: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 206 | self.logger.info('_update_break_state(%r)' % (self._break_state,)) |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 207 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 208 | def _update_rts_state(self): |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 209 | """Set terminal status line: Request To Send""" |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 210 | if self.logger: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 211 | self.logger.info('_update_rts_state(%r) -> state of CTS' % (self._rts_state,)) |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 212 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 213 | def _update_dtr_state(self): |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 214 | """Set terminal status line: Data Terminal Ready""" |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 215 | if self.logger: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 216 | self.logger.info('_update_dtr_state(%r) -> state of DSR' % (self._dtr_state,)) |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 217 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 218 | @property |
| 219 | def cts(self): |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 220 | """Read terminal status line: Clear To Send""" |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 221 | if not self.is_open: raise portNotOpenError |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 222 | if self.logger: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 223 | self.logger.info('CTS -> state of RTS (%r)' % (self._rts_state,)) |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 224 | return self._rts_state |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 225 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 226 | @property |
| 227 | def dsr(self): |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 228 | """Read terminal status line: Data Set Ready""" |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 229 | if self.logger: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 230 | self.logger.info('DSR -> state of DTR (%r)' % (self._dtr_state,)) |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 231 | return self._dtr_state |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 232 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 233 | @property |
| 234 | def ri(self): |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 235 | """Read terminal status line: Ring Indicator""" |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 236 | if not self.is_open: raise portNotOpenError |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 237 | if self.logger: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 238 | self.logger.info('returning dummy for RI') |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 239 | return False |
| 240 | |
Chris Liechti | ef1fe25 | 2015-08-27 23:25:21 +0200 | [diff] [blame] | 241 | @property |
| 242 | def cd(self): |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 243 | """Read terminal status line: Carrier Detect""" |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 244 | if not self.is_open: raise portNotOpenError |
cliechti | 6a30077 | 2009-08-12 02:28:56 +0000 | [diff] [blame] | 245 | if self.logger: |
Chris Liechti | 3ad62fb | 2015-08-29 21:53:32 +0200 | [diff] [blame^] | 246 | self.logger.info('returning dummy for CD') |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 247 | return True |
| 248 | |
| 249 | # - - - platform specific - - - |
| 250 | # None so far |
| 251 | |
| 252 | |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 253 | # simple client test |
| 254 | if __name__ == '__main__': |
| 255 | import sys |
cliechti | ab3d428 | 2011-08-19 01:52:46 +0000 | [diff] [blame] | 256 | s = Serial('loop://') |
cliechti | 41973a9 | 2009-08-06 02:18:21 +0000 | [diff] [blame] | 257 | sys.stdout.write('%s\n' % s) |
| 258 | |
| 259 | sys.stdout.write("write...\n") |
| 260 | s.write("hello\n") |
| 261 | s.flush() |
| 262 | sys.stdout.write("read: %s\n" % s.read(5)) |
| 263 | |
| 264 | s.close() |