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