@@ -207,12 +207,24 @@ async def restart_simulation(self, pause: bool = False) -> ResponseMessage:
207207 """
208208 return await restart (self ._transport , pause )
209209
210- async def serial_monitor_cat (self ) -> None :
210+ async def serial_monitor_cat (self , decode_utf8 : bool = True , errors : str = "replace" ) -> None :
211211 """
212212 Print serial monitor output to stdout as it is received from the simulation.
213+
214+ Args:
215+ decode_utf8: Whether to decode bytes as UTF-8. If False, prints raw bytes (default: True).
216+ errors: How to handle UTF-8 decoding errors. Options: 'strict', 'ignore', 'replace' (default: 'replace').
213217 """
214218 async for line in monitor_lines (self ._transport ):
215- print (line .decode ("utf-8" ), end = "" , flush = True )
219+ if decode_utf8 :
220+ try :
221+ output = line .decode ("utf-8" , errors = errors )
222+ print (output , end = "" , flush = True )
223+ except UnicodeDecodeError :
224+ # Fallback to raw bytes if decoding fails completely
225+ print (line , end = "" , flush = True )
226+ else :
227+ print (line , end = "" , flush = True )
216228
217229 async def serial_write (self , data : typing .Union [bytes , str , list [int ]]) -> None :
218230 """Write data to the simulation serial monitor interface."""
0 commit comments