@@ -196,12 +196,12 @@ def _wait_timeout(self) -> None:
196
196
while time .monotonic () < self ._resume :
197
197
pass
198
198
199
- def _write_char (self , char : str ) -> None :
199
+ def _write_char (self , char : str , * , encoding : str = "utf-8" ) -> None :
200
200
# Write a single character to the printer.
201
201
if char == "\r " :
202
202
return # Strip carriage returns by skipping them.
203
203
self ._wait_timeout ()
204
- self ._uart .write (bytes (char , "ascii" ))
204
+ self ._uart .write (bytes (char , encoding ))
205
205
delay = self ._byte_delay_s
206
206
# Add extra delay for newlines or moving past the last column.
207
207
if char == "\n " or self ._column == self ._max_column :
@@ -298,15 +298,21 @@ def reset(self) -> None:
298
298
# ESC + 'D' + tab stop value list ending with null to terminate.
299
299
self .send_command ("\x1B D\x04 \x08 \x10 \x14 \x18 \x1C \x00 " )
300
300
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 :
302
304
"""Print a line of text. Optionally specify the end keyword to
303
305
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.
305
311
"""
306
312
for char in text :
307
- self ._write_char (char )
313
+ self ._write_char (char , encoding = encoding )
308
314
if end is not None :
309
- self ._write_char (end )
315
+ self ._write_char (end , encoding = encoding )
310
316
311
317
def print_barcode (self , text : str , barcode_type : int ) -> None :
312
318
"""Print a barcode with the specified text/number (the meaning
0 commit comments