FIX all calls of _raw(), (except in images) in escpos

bytes should now be used in all but the image functions reliably
This commit is contained in:
Patrick Kanzler 2016-03-03 04:38:05 +01:00
parent 5d5412ba73
commit c9ea90cd82
1 changed files with 9 additions and 7 deletions

View File

@ -83,7 +83,7 @@ class Escpos(object):
""" """
i = 0 i = 0
cont = 0 cont = 0
pbuffer = "" pbuffer = b''
self._raw(S_RASTER_N) self._raw(S_RASTER_N)
pbuffer = "%02X%02X%02X%02X" % (((size[0]/size[1])/8), 0, size[1] & 0xff, size[1] >> 8) pbuffer = "%02X%02X%02X%02X" % (((size[0]/size[1])/8), 0, size[1] & 0xff, size[1] >> 8)
@ -408,12 +408,12 @@ class Escpos(object):
self._raw(TXT_ALIGN_CT) self._raw(TXT_ALIGN_CT)
# Height # Height
if 1 <= height <= 255: if 1 <= height <= 255:
self._raw(BARCODE_HEIGHT + chr(height)) self._raw(BARCODE_HEIGHT + six.int2byte(height))
else: else:
raise BarcodeSizeError("height = {height}".format(height=height)) raise BarcodeSizeError("height = {height}".format(height=height))
# Width # Width
if 2 <= width <= 6: if 2 <= width <= 6:
self._raw(BARCODE_WIDTH + chr(width)) self._raw(BARCODE_WIDTH + six.int2byte(width))
else: else:
raise BarcodeSizeError("width = {width}".format(width=width)) raise BarcodeSizeError("width = {width}".format(width=width))
# Font # Font
@ -446,7 +446,7 @@ class Escpos(object):
# Print Code # Print Code
if code: if code:
self._raw(code) self._raw(code.encode())
else: else:
raise BarcodeCodeError() raise BarcodeCodeError()
@ -458,11 +458,13 @@ class Escpos(object):
The text has to be encoded in the currently selected codepage. The text has to be encoded in the currently selected codepage.
.. todo:: rework this in order to proberly handle encoding
:param txt: text to be printed :param txt: text to be printed
:raises: :py:exc:`~escpos.exceptions.TextError` :raises: :py:exc:`~escpos.exceptions.TextError`
""" """
if txt: if txt:
self._raw(txt) self._raw(txt.encode())
else: else:
# TODO: why is it problematic to print an empty string? # TODO: why is it problematic to print an empty string?
raise TextError() raise TextError()
@ -602,7 +604,7 @@ class Escpos(object):
""" """
# Fix the size between last line and cut # Fix the size between last line and cut
# TODO: handle this with a line feed # TODO: handle this with a line feed
self._raw("\n\n\n\n\n\n") self._raw(b"\n\n\n\n\n\n")
if mode.upper() == "PART": if mode.upper() == "PART":
self._raw(PAPER_PART_CUT) self._raw(PAPER_PART_CUT)
else: # DEFAULT MODE: FULL CUT else: # DEFAULT MODE: FULL CUT
@ -659,7 +661,7 @@ class Escpos(object):
if pos < 1 or pos > 16: if pos < 1 or pos > 16:
raise TabPosError() raise TabPosError()
else: else:
self._raw("".join([CTL_SET_HT, hex(pos)])) self._raw(CTL_SET_HT + six.int2byte(pos))
# Set position # Set position
if ctl.upper() == "LF": if ctl.upper() == "LF":
self._raw(CTL_LF) self._raw(CTL_LF)