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

encode strings / chars as ascii before sending to the printer #5

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions adafruit_thermal_printer/thermal_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _write_char(self, char):
if char == '\r':
return # Strip carriage returns by skipping them.
self._wait_timeout()
self._uart.write(char)
self._uart.write(char.encode('ascii'))
delay = self._byte_delay_s
# Add extra delay for newlines or moving past the last column.
if char == '\n' or self._column == self._max_column:
Expand Down Expand Up @@ -238,7 +238,7 @@ def _unset_print_mode(self, mask):

def send_command(self, command):
"""Send a command string to the printer."""
self._uart.write(command)
self._uart.write(command.encode('ascii'))

# Do initialization in warm_up instead of the initializer because this
# initialization takes a long time (5 seconds) and shouldn't happen during
Expand Down
5 changes: 4 additions & 1 deletion examples/thermal_printer_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import adafruit_thermal_printer


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

# For a computer, use the pyserial library for uart access.
# import serial
# uart = serial.Serial("/dev/serial0", baudrate=19200, timeout=3000)

# Create the printer instance.
printer = ThermalPrinter(uart, auto_warm_up=False)

Expand Down