Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/wokwi_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,24 @@ async def restart_simulation(self, pause: bool = False) -> ResponseMessage:
"""
return await restart(self._transport, pause)

async def serial_monitor_cat(self) -> None:
async def serial_monitor_cat(self, decode_utf8: bool = True, errors: str = "replace") -> None:
"""
Print serial monitor output to stdout as it is received from the simulation.

Args:
decode_utf8: Whether to decode bytes as UTF-8. If False, prints raw bytes (default: True).
errors: How to handle UTF-8 decoding errors. Options: 'strict', 'ignore', 'replace' (default: 'replace').
"""
async for line in monitor_lines(self._transport):
print(line.decode("utf-8"), end="", flush=True)
if decode_utf8:
try:
output = line.decode("utf-8", errors=errors)
print(output, end="", flush=True)
except UnicodeDecodeError:
# Fallback to raw bytes if decoding fails completely
print(line, end="", flush=True)
else:
print(line, end="", flush=True)

def _on_pause(self, event: EventMessage) -> None:
self.last_pause_nanos = int(event["nanos"])
Loading