Read size bytes from the serial port. If a timeout is set it may return less characters as requested. With no timeout it will block until the requested number of bytes is read.
(self, size=1)
| 150 | return self._instream.available() |
| 151 | |
| 152 | def read(self, size=1): |
| 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 | if not self.sPort: raise portNotOpenError |
| 157 | read = bytearray() |
| 158 | if size > 0: |
| 159 | while len(read) < size: |
| 160 | x = self._instream.read() |
| 161 | if x == -1: |
| 162 | if self.timeout >= 0: |
| 163 | break |
| 164 | else: |
| 165 | read.append(x) |
| 166 | return bytes(read) |
| 167 | |
| 168 | def write(self, data): |
| 169 | """Output the given string over the serial port.""" |
no test coverage detected