@@ -172,12 +172,24 @@ async def restart_simulation(self, pause: bool = False) -> ResponseMessage:
172172 """
173173 return await restart (self ._transport , pause )
174174
175- async def serial_monitor_cat (self ) -> None :
175+ async def serial_monitor_cat (self , decode_utf8 : bool = True , errors : str = "replace" ) -> None :
176176 """
177177 Print serial monitor output to stdout as it is received from the simulation.
178+
179+ Args:
180+ decode_utf8: Whether to decode bytes as UTF-8. If False, prints raw bytes (default: True).
181+ errors: How to handle UTF-8 decoding errors. Options: 'strict', 'ignore', 'replace' (default: 'replace').
178182 """
179183 async for line in monitor_lines (self ._transport ):
180- print (line .decode ("utf-8" ), end = "" , flush = True )
184+ if decode_utf8 :
185+ try :
186+ output = line .decode ("utf-8" , errors = errors )
187+ print (output , end = "" , flush = True )
188+ except UnicodeDecodeError :
189+ # Fallback to raw bytes if decoding fails completely
190+ print (line , end = "" , flush = True )
191+ else :
192+ print (line , end = "" , flush = True )
181193
182194 def _on_pause (self , event : EventMessage ) -> None :
183195 self .last_pause_nanos = int (event ["nanos" ])
0 commit comments