Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.

Commit 7aabf5c

Browse files
authored
Merge pull request #5 from adafruit/ascii_encoding
encode strings / chars as ascii before sending to the printer
2 parents 9d776c7 + 7e361b6 commit 7aabf5c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

adafruit_thermal_printer/thermal_printer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _write_char(self, char):
202202
if char == '\r':
203203
return # Strip carriage returns by skipping them.
204204
self._wait_timeout()
205-
self._uart.write(char)
205+
self._uart.write(char.encode('ascii'))
206206
delay = self._byte_delay_s
207207
# Add extra delay for newlines or moving past the last column.
208208
if char == '\n' or self._column == self._max_column:
@@ -238,7 +238,7 @@ def _unset_print_mode(self, mask):
238238

239239
def send_command(self, command):
240240
"""Send a command string to the printer."""
241-
self._uart.write(command)
241+
self._uart.write(command.encode('ascii'))
242242

243243
# Do initialization in warm_up instead of the initializer because this
244244
# initialization takes a long time (5 seconds) and shouldn't happen during

examples/thermal_printer_simpletest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import adafruit_thermal_printer
77

8-
98
# Pick which version thermal printer class to use depending on the version of
109
# your printer. Hold the button on the printer as it's powered on and it will
1110
# print a test page that displays the firmware version, like 2.64, 2.68, etc.
@@ -25,6 +24,10 @@
2524
# during power-up and it will show the baud rate). Most printers use 19200.
2625
uart = busio.UART(TX, RX, baudrate=19200)
2726

27+
# For a computer, use the pyserial library for uart access.
28+
# import serial
29+
# uart = serial.Serial("/dev/serial0", baudrate=19200, timeout=3000)
30+
2831
# Create the printer instance.
2932
printer = ThermalPrinter(uart, auto_warm_up=False)
3033

0 commit comments

Comments
 (0)