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

Conversation

brennen
Copy link
Contributor

@brennen brennen commented Oct 2, 2018

This or something like it seems to be necessary on CPython - otherwise you get a bunch of:

Traceback (most recent call last):
  File "thermal_printer_simpletest.py", line 32, in <module>
    printer = ThermalPrinter(uart, auto_warm_up=False)
  File "/home/pi/Adafruit_CircuitPython_Thermal_Printer/.env/lib/python3.5/site-packages/adafruit_circuitpython_thermal_printer-1.1.1.dev1+g9d776c7.d20181002-py3.5.egg/adafruit_thermal_printer/thermal_printer.py", line 187, in __init__
  File "/home/pi/Adafruit_CircuitPython_Thermal_Printer/.env/lib/python3.5/site-packages/adafruit_circuitpython_thermal_printer-1.1.1.dev1+g9d776c7.d20181002-py3.5.egg/adafruit_thermal_printer/thermal_printer.py", line 289, in reset
  File "/home/pi/Adafruit_CircuitPython_Thermal_Printer/.env/lib/python3.5/site-packages/adafruit_circuitpython_thermal_printer-1.1.1.dev1+g9d776c7.d20181002-py3.5.egg/adafruit_thermal_printer/thermal_printer.py", line 241, in send_command
  File "/home/pi/Adafruit_CircuitPython_Thermal_Printer/.env/lib/python3.5/site-packages/serial/serialposix.py", line 532, in write
    d = to_bytes(data)
  File "/home/pi/Adafruit_CircuitPython_Thermal_Printer/.env/lib/python3.5/site-packages/serial/serialutil.py", line 63, in to_bytes
    raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: '\x1b@'

I'm unsure if this is the right way to handle the problem, or if I caught everything, but the simpletest runs with these changes. Thoughts?

(Hasn't yet been tested on CircuitPython hardware, also includes pyserial line in simpletest.)

This seems to be necessary on CPython.  I'm unsure if this is the right way
to handle the problem, or if I caught everything, but the simpletest runs
with these changes.

Hasn't yet been tested on CircuitPython hardware.
@brennen brennen requested review from tannewt and ladyada October 2, 2018 22:59
@ladyada ladyada merged commit 7aabf5c into master Oct 2, 2018
@ladyada
Copy link
Member

ladyada commented Oct 2, 2018

oh yeah you can see the PR i did on GPS for the same thing, its a circuitpy vs py3 difference. not hard but you gotta do it

@brennen brennen deleted the ascii_encoding branch October 3, 2018 21:30
tannewt pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Oct 4, 2018
Updating https://github.com/adafruit/Adafruit_CircuitPython_Thermal_Printer to 1.1.1 from 1.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Thermal_Printer#6 from adafruit/require_pyserial
  > Merge pull request adafruit/Adafruit_CircuitPython_Thermal_Printer#5 from adafruit/ascii_encoding
  > ignore the board module imports in .pylintrc

Updating https://github.com/adafruit/Adafruit_CircuitPython_VC0706 to 4.0.1 from 4.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_VC0706#6 from adafruit/require_pyserial
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants