cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 1 | #! python |
cliechti | ff0c379 | 2008-06-22 01:01:21 +0000 | [diff] [blame] | 2 | # Python Serial Port Extension for Win32, Linux, BSD, Jython and .NET/Mono |
| 3 | # serial driver for .NET/Mono (IronPython), .NET >= 2 |
| 4 | # see __init__.py |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 5 | # |
Chris Liechti | c2b2679 | 2015-09-22 23:16:07 +0200 | [diff] [blame^] | 6 | # (C) 2008-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 | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 9 | |
cliechti | 761fd6e | 2008-06-24 11:32:43 +0000 | [diff] [blame] | 10 | import clr |
| 11 | import System |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 12 | import System.IO.Ports |
cliechti | 39cfb7b | 2011-08-22 00:30:07 +0000 | [diff] [blame] | 13 | from serial.serialutil import * |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 14 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 15 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 16 | #~ def device(portnum): |
| 17 | #~ """Turn a port number into a device name""" |
| 18 | #~ return System.IO.Ports.SerialPort.GetPortNames()[portnum] |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 19 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 20 | |
cliechti | 761fd6e | 2008-06-24 11:32:43 +0000 | [diff] [blame] | 21 | # must invoke function with byte array, make a helper to convert strings |
| 22 | # to byte arrays |
| 23 | sab = System.Array[System.Byte] |
| 24 | def as_byte_array(string): |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 25 | return sab([ord(x) for x in string]) # XXX will require adaption when run with a 3.x compatible IronPython |
cliechti | 761fd6e | 2008-06-24 11:32:43 +0000 | [diff] [blame] | 26 | |
Chris Liechti | ef6b7b4 | 2015-08-06 22:19:26 +0200 | [diff] [blame] | 27 | class Serial(SerialBase): |
cliechti | 771278b | 2013-10-17 03:19:00 +0000 | [diff] [blame] | 28 | """Serial port implementation for .NET/Mono.""" |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 29 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 30 | BAUDRATES = (50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, |
| 31 | 9600, 19200, 38400, 57600, 115200) |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 32 | |
| 33 | def open(self): |
cliechti | 00df970 | 2014-08-04 10:12:48 +0000 | [diff] [blame] | 34 | """\ |
| 35 | Open port with current settings. This may throw a SerialException |
| 36 | if the port cannot be opened. |
| 37 | """ |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 38 | if self._port is None: |
| 39 | raise SerialException("Port must be configured before it can be used.") |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 40 | if self.is_open: |
cliechti | 8f69e70 | 2011-03-19 00:22:32 +0000 | [diff] [blame] | 41 | raise SerialException("Port is already open.") |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 42 | try: |
| 43 | self._port_handle = System.IO.Ports.SerialPort(self.portstr) |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 44 | except Exception as msg: |
cliechti | ff0c379 | 2008-06-22 01:01:21 +0000 | [diff] [blame] | 45 | self._port_handle = None |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 46 | raise SerialException("could not open port %s: %s" % (self.portstr, msg)) |
| 47 | |
| 48 | self._reconfigurePort() |
| 49 | self._port_handle.Open() |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 50 | self.is_open = True |
| 51 | if not self._dsrdtr: |
| 52 | self._update_dtr_state() |
cliechti | 761fd6e | 2008-06-24 11:32:43 +0000 | [diff] [blame] | 53 | if not self._rtscts: |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 54 | self._update_rts_state() |
| 55 | self.reset_input_buffer() |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 56 | |
| 57 | def _reconfigurePort(self): |
cliechti | ff0c379 | 2008-06-22 01:01:21 +0000 | [diff] [blame] | 58 | """Set communication parameters on opened port.""" |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 59 | if not self._port_handle: |
| 60 | raise SerialException("Can only operate on a valid port handle") |
cliechti | 58b481c | 2009-02-16 20:42:32 +0000 | [diff] [blame] | 61 | |
cliechti | edfba4e | 2009-02-07 00:29:47 +0000 | [diff] [blame] | 62 | #~ self._port_handle.ReceivedBytesThreshold = 1 |
cliechti | 58b481c | 2009-02-16 20:42:32 +0000 | [diff] [blame] | 63 | |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 64 | if self._timeout is None: |
| 65 | self._port_handle.ReadTimeout = System.IO.Ports.SerialPort.InfiniteTimeout |
| 66 | else: |
| 67 | self._port_handle.ReadTimeout = int(self._timeout*1000) |
cliechti | 58b481c | 2009-02-16 20:42:32 +0000 | [diff] [blame] | 68 | |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 69 | # if self._timeout != 0 and self._interCharTimeout is not None: |
| 70 | # timeouts = (int(self._interCharTimeout * 1000),) + timeouts[1:] |
cliechti | 58b481c | 2009-02-16 20:42:32 +0000 | [diff] [blame] | 71 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 72 | if self._write_timeout is None: |
cliechti | ff0c379 | 2008-06-22 01:01:21 +0000 | [diff] [blame] | 73 | self._port_handle.WriteTimeout = System.IO.Ports.SerialPort.InfiniteTimeout |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 74 | else: |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 75 | self._port_handle.WriteTimeout = int(self._write_timeout*1000) |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | # Setup the connection info. |
cliechti | c53a8ca | 2008-06-24 11:57:32 +0000 | [diff] [blame] | 79 | try: |
| 80 | self._port_handle.BaudRate = self._baudrate |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 81 | except IOError as e: |
cliechti | c53a8ca | 2008-06-24 11:57:32 +0000 | [diff] [blame] | 82 | # catch errors from illegal baudrate settings |
| 83 | raise ValueError(str(e)) |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 84 | |
| 85 | if self._bytesize == FIVEBITS: |
| 86 | self._port_handle.DataBits = 5 |
| 87 | elif self._bytesize == SIXBITS: |
| 88 | self._port_handle.DataBits = 6 |
| 89 | elif self._bytesize == SEVENBITS: |
| 90 | self._port_handle.DataBits = 7 |
| 91 | elif self._bytesize == EIGHTBITS: |
| 92 | self._port_handle.DataBits = 8 |
| 93 | else: |
| 94 | raise ValueError("Unsupported number of data bits: %r" % self._bytesize) |
| 95 | |
| 96 | if self._parity == PARITY_NONE: |
cliechti | 91d247d | 2009-07-25 00:42:57 +0000 | [diff] [blame] | 97 | self._port_handle.Parity = getattr(System.IO.Ports.Parity, 'None') # reserved keyword in Py3k |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 98 | elif self._parity == PARITY_EVEN: |
| 99 | self._port_handle.Parity = System.IO.Ports.Parity.Even |
| 100 | elif self._parity == PARITY_ODD: |
| 101 | self._port_handle.Parity = System.IO.Ports.Parity.Odd |
| 102 | elif self._parity == PARITY_MARK: |
| 103 | self._port_handle.Parity = System.IO.Ports.Parity.Mark |
| 104 | elif self._parity == PARITY_SPACE: |
| 105 | self._port_handle.Parity = System.IO.Ports.Parity.Space |
| 106 | else: |
| 107 | raise ValueError("Unsupported parity mode: %r" % self._parity) |
| 108 | |
| 109 | if self._stopbits == STOPBITS_ONE: |
| 110 | self._port_handle.StopBits = System.IO.Ports.StopBits.One |
cliechti | 58b481c | 2009-02-16 20:42:32 +0000 | [diff] [blame] | 111 | elif self._stopbits == STOPBITS_ONE_POINT_FIVE: |
| 112 | self._port_handle.StopBits = System.IO.Ports.StopBits.OnePointFive |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 113 | elif self._stopbits == STOPBITS_TWO: |
| 114 | self._port_handle.StopBits = System.IO.Ports.StopBits.Two |
| 115 | else: |
| 116 | raise ValueError("Unsupported number of stop bits: %r" % self._stopbits) |
cliechti | 58b481c | 2009-02-16 20:42:32 +0000 | [diff] [blame] | 117 | |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 118 | if self._rtscts and self._xonxoff: |
| 119 | self._port_handle.Handshake = System.IO.Ports.Handshake.RequestToSendXOnXOff |
| 120 | elif self._rtscts: |
| 121 | self._port_handle.Handshake = System.IO.Ports.Handshake.RequestToSend |
| 122 | elif self._xonxoff: |
| 123 | self._port_handle.Handshake = System.IO.Ports.Handshake.XOnXOff |
| 124 | else: |
cliechti | 91d247d | 2009-07-25 00:42:57 +0000 | [diff] [blame] | 125 | self._port_handle.Handshake = getattr(System.IO.Ports.Handshake, 'None') # reserved keyword in Py3k |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 126 | |
| 127 | #~ def __del__(self): |
| 128 | #~ self.close() |
| 129 | |
| 130 | def close(self): |
| 131 | """Close port""" |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 132 | if self.is_open: |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 133 | if self._port_handle: |
| 134 | try: |
cliechti | ff0c379 | 2008-06-22 01:01:21 +0000 | [diff] [blame] | 135 | self._port_handle.Close() |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 136 | except System.IO.Ports.InvalidOperationException: |
| 137 | # ignore errors. can happen for unplugged USB serial devices |
| 138 | pass |
| 139 | self._port_handle = None |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 140 | self.is_open = False |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 141 | |
| 142 | # - - - - - - - - - - - - - - - - - - - - - - - - |
cliechti | 58b481c | 2009-02-16 20:42:32 +0000 | [diff] [blame] | 143 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 144 | @property |
| 145 | def in_waiting(self): |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 146 | """Return the number of characters currently in the input buffer.""" |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 147 | if not self._port_handle: |
| 148 | raise portNotOpenError |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 149 | return self._port_handle.BytesToRead |
| 150 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 151 | def read(self, size=1): |
cliechti | 00df970 | 2014-08-04 10:12:48 +0000 | [diff] [blame] | 152 | """\ |
| 153 | Read size bytes from the serial port. If a timeout is set it may |
| 154 | return less characters as requested. With no timeout it will block |
| 155 | until the requested number of bytes is read. |
| 156 | """ |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 157 | if not self._port_handle: |
| 158 | raise portNotOpenError |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 159 | # must use single byte reads as this is the only way to read |
| 160 | # without applying encodings |
| 161 | data = bytearray() |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 162 | while size: |
cliechti | ff0c379 | 2008-06-22 01:01:21 +0000 | [diff] [blame] | 163 | try: |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 164 | data.append(self._port_handle.ReadByte()) |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 165 | except System.TimeoutException as e: |
cliechti | ff0c379 | 2008-06-22 01:01:21 +0000 | [diff] [blame] | 166 | break |
| 167 | else: |
| 168 | size -= 1 |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 169 | return bytes(data) |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 170 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 171 | def write(self, data): |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 172 | """Output the given string over the serial port.""" |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 173 | if not self._port_handle: |
| 174 | raise portNotOpenError |
cliechti | 00df970 | 2014-08-04 10:12:48 +0000 | [diff] [blame] | 175 | #~ if not isinstance(data, (bytes, bytearray)): |
| 176 | #~ raise TypeError('expected %s or bytearray, got %s' % (bytes, type(data))) |
cliechti | ff0c379 | 2008-06-22 01:01:21 +0000 | [diff] [blame] | 177 | try: |
cliechti | 761fd6e | 2008-06-24 11:32:43 +0000 | [diff] [blame] | 178 | # must call overloaded method with byte array argument |
| 179 | # as this is the only one not applying encodings |
| 180 | self._port_handle.Write(as_byte_array(data), 0, len(data)) |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 181 | except System.TimeoutException as e: |
cliechti | ff0c379 | 2008-06-22 01:01:21 +0000 | [diff] [blame] | 182 | raise writeTimeoutError |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 183 | return len(data) |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 184 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 185 | def reset_input_buffer(self): |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 186 | """Clear input buffer, discarding all that is in the buffer.""" |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 187 | if not self._port_handle: |
| 188 | raise portNotOpenError |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 189 | self._port_handle.DiscardInBuffer() |
| 190 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 191 | def reset_output_buffer(self): |
cliechti | 00df970 | 2014-08-04 10:12:48 +0000 | [diff] [blame] | 192 | """\ |
| 193 | Clear output buffer, aborting the current output and |
| 194 | discarding all that is in the buffer. |
| 195 | """ |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 196 | if not self._port_handle: |
| 197 | raise portNotOpenError |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 198 | self._port_handle.DiscardOutBuffer() |
| 199 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 200 | def _update_break_state(self): |
cliechti | 00df970 | 2014-08-04 10:12:48 +0000 | [diff] [blame] | 201 | """ |
| 202 | Set break: Controls TXD. When active, to transmitting is possible. |
| 203 | """ |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 204 | if not self._port_handle: |
| 205 | raise portNotOpenError |
| 206 | self._port_handle.BreakState = bool(self._break_state) |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 207 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 208 | def _update_rts_state(self): |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 209 | """Set terminal status line: Request To Send""" |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 210 | if not self._port_handle: |
| 211 | raise portNotOpenError |
| 212 | self._port_handle.RtsEnable = bool(self._rts_state) |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 213 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 214 | def _update_dtr_state(self): |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 215 | """Set terminal status line: Data Terminal Ready""" |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 216 | if not self._port_handle: |
| 217 | raise portNotOpenError |
| 218 | self._port_handle.DtrEnable = bool(self._dtr_state) |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 219 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 220 | @property |
| 221 | def cts(self): |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 222 | """Read terminal status line: Clear To Send""" |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 223 | if not self._port_handle: |
| 224 | raise portNotOpenError |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 225 | return self._port_handle.CtsHolding |
| 226 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 227 | @property |
| 228 | def dsr(self): |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 229 | """Read terminal status line: Data Set Ready""" |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 230 | if not self._port_handle: |
| 231 | raise portNotOpenError |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 232 | return self._port_handle.DsrHolding |
| 233 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 234 | @property |
| 235 | def ri(self): |
cliechti | ff0c379 | 2008-06-22 01:01:21 +0000 | [diff] [blame] | 236 | """Read terminal status line: Ring Indicator""" |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 237 | if not self._port_handle: |
| 238 | raise portNotOpenError |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 239 | #~ return self._port_handle.XXX |
cliechti | ff0c379 | 2008-06-22 01:01:21 +0000 | [diff] [blame] | 240 | return False #XXX an error would be better |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 241 | |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 242 | @property |
| 243 | def cd(self): |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 244 | """Read terminal status line: Carrier Detect""" |
Chris Liechti | 6ed12e0 | 2015-09-18 21:23:42 +0200 | [diff] [blame] | 245 | if not self._port_handle: |
| 246 | raise portNotOpenError |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 247 | return self._port_handle.CDHolding |
| 248 | |
| 249 | # - - platform specific - - - - |
cliechti | f81362e | 2009-07-25 03:44:33 +0000 | [diff] [blame] | 250 | # none |
| 251 | |
| 252 | |
cliechti | 4a567a0 | 2009-07-27 22:09:31 +0000 | [diff] [blame] | 253 | # Nur Testfunktion!! |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 254 | if __name__ == '__main__': |
cliechti | 7aaead3 | 2009-07-23 14:02:41 +0000 | [diff] [blame] | 255 | import sys |
| 256 | |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 257 | s = Serial(0) |
cliechti | 7aaead3 | 2009-07-23 14:02:41 +0000 | [diff] [blame] | 258 | sys.stdio.write('%s\n' % s) |
| 259 | |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 260 | s = Serial() |
cliechti | 7aaead3 | 2009-07-23 14:02:41 +0000 | [diff] [blame] | 261 | sys.stdio.write('%s\n' % s) |
| 262 | |
| 263 | |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 264 | s.baudrate = 19200 |
| 265 | s.databits = 7 |
| 266 | s.close() |
| 267 | s.port = 0 |
| 268 | s.open() |
cliechti | 7aaead3 | 2009-07-23 14:02:41 +0000 | [diff] [blame] | 269 | sys.stdio.write('%s\n' % s) |
cliechti | 0d6029a | 2008-06-21 01:28:46 +0000 | [diff] [blame] | 270 | |