MCPcopy Create free account
hub / github.com/FastLED/FastLED / write

Method write

ci/util/pyserial_monitor.py:186–212  ·  view source on GitHub ↗

Write data to serial port. Args: data: String or bytes to write to serial port Returns: Number of bytes written Raises: RuntimeError: If not attached or write fails

(self, data: str | bytes)

Source from the content-addressed store, hash-verified

184 raise
185
186 def write(self, data: str | bytes) -> int:
187 """Write data to serial port.
188
189 Args:
190 data: String or bytes to write to serial port
191
192 Returns:
193 Number of bytes written
194
195 Raises:
196 RuntimeError: If not attached or write fails
197 """
198 if not self._attached or not self._ser:
199 raise RuntimeError("Cannot write: not attached")
200
201 try:
202 # Convert string to bytes if needed
203 if isinstance(data, str):
204 data_bytes = data.encode("utf-8")
205 else:
206 data_bytes = data
207
208 bytes_written = self._ser.write(data_bytes)
209 self._ser.flush()
210 return bytes_written or 0
211 except serial.SerialException as e:
212 raise RuntimeError(f"Serial write error: {e}") from e

Callers

nothing calls this directly

Calls 1

flushMethod · 0.45

Tested by

no test coverage detected