@@ -196,12 +196,12 @@ def _wait_timeout(self) -> None:
196196 while time .monotonic () < self ._resume :
197197 pass
198198
199- def _write_char (self , char : str ) -> None :
199+ def _write_char (self , char : str , * , encoding : str = "utf-8" ) -> None :
200200 # Write a single character to the printer.
201201 if char == "\r " :
202202 return # Strip carriage returns by skipping them.
203203 self ._wait_timeout ()
204- self ._uart .write (bytes (char , "ascii" ))
204+ self ._uart .write (bytes (char , encoding ))
205205 delay = self ._byte_delay_s
206206 # Add extra delay for newlines or moving past the last column.
207207 if char == "\n " or self ._column == self ._max_column :
@@ -298,15 +298,21 @@ def reset(self) -> None:
298298 # ESC + 'D' + tab stop value list ending with null to terminate.
299299 self .send_command ("\x1B D\x04 \x08 \x10 \x14 \x18 \x1C \x00 " )
300300
301- def print (self , text : str , end : Optional [str ] = "\n " ) -> None :
301+ def print (
302+ self , text : str , end : Optional [str ] = "\n " , * , encoding : str = "utf-8"
303+ ) -> None :
302304 """Print a line of text. Optionally specify the end keyword to
303305 override the new line printed after the text (set to None to disable
304- the new line entirely).
306+ the new line entirely). Optionally specify the encoding. Some
307+ printers only accept the more restrictive encodings "cp437" and
308+ "ascii".
309+ Note: Encodings other than "utf-8" are not accepted by
310+ microcontrollers.
305311 """
306312 for char in text :
307- self ._write_char (char )
313+ self ._write_char (char , encoding = encoding )
308314 if end is not None :
309- self ._write_char (end )
315+ self ._write_char (end , encoding = encoding )
310316
311317 def print_barcode (self , text : str , barcode_type : int ) -> None :
312318 """Print a barcode with the specified text/number (the meaning
0 commit comments