How to use the escpos.barcode function in escpos

To help you get started, we’ve selected a few escpos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github base4sistemas / pyescpos / escpos / impl / daruma.py View on Github external
def _translate_barcode_hri(value):
    values = {
            barcode.BARCODE_HRI_NONE: 0,
            barcode.BARCODE_HRI_TOP: 0,
            barcode.BARCODE_HRI_BOTTOM: 1,
            barcode.BARCODE_HRI_BOTH: 0,
        }
    return values.get(value)
github base4sistemas / pyescpos / escpos / impl / epson.py View on Github external
def _get_qrcode_module_size(**kwargs):
    return QRCODE_MODULE_SIZE_MAP[kwargs.get('qrcode_module_size',
            barcode.QRCODE_MODULE_SIZE_4)]
github base4sistemas / pyescpos / escpos / impl / daruma.py View on Github external
def _translate_barcode_width(value):
    values = {
            barcode.BARCODE_NORMAL_WIDTH: 2,
            barcode.BARCODE_DOUBLE_WIDTH: 3,
            barcode.BARCODE_QUADRUPLE_WIDTH: 5,
        }
    return values.get(value)
github base4sistemas / pyescpos / escpos / impl / bematech.py View on Github external
def _barcode_configure(self, **kwargs):
        if 'barcode_height' in kwargs:
            barcode_height = kwargs.get('barcode_height')
            self._impl.device.write('\x1D\x68' + chr(barcode_height))

        if 'barcode_width' in kwargs:
            widths = {
                    barcode.BARCODE_NORMAL_WIDTH: 2,
                    barcode.BARCODE_DOUBLE_WIDTH: 3,
                    barcode.BARCODE_QUADRUPLE_WIDTH: 4,}
            barcode_width = widths.get(kwargs.get('barcode_width'))
            self._impl.device.write('\x1D\x77' + chr(barcode_width))

        if 'barcode_hri' in kwargs:
            values = {
                    barcode.BARCODE_HRI_NONE: 0,
                    barcode.BARCODE_HRI_TOP: 1,
                    barcode.BARCODE_HRI_BOTTOM: 2,
                    barcode.BARCODE_HRI_BOTH: 3,}
            barcode_hri = values.get(kwargs.get('barcode_hri'))
            self._impl.device.write('\x1D\x48' + chr(barcode_hri))
github base4sistemas / pyescpos / escpos / impl / bematech.py View on Github external
def _barcode_configure(self, **kwargs):
        if 'barcode_height' in kwargs:
            barcode_height = kwargs.get('barcode_height')
            self._impl.device.write('\x1D\x68' + chr(barcode_height))

        if 'barcode_width' in kwargs:
            widths = {
                    barcode.BARCODE_NORMAL_WIDTH: 2,
                    barcode.BARCODE_DOUBLE_WIDTH: 3,
                    barcode.BARCODE_QUADRUPLE_WIDTH: 4,}
            barcode_width = widths.get(kwargs.get('barcode_width'))
            self._impl.device.write('\x1D\x77' + chr(barcode_width))

        if 'barcode_hri' in kwargs:
            values = {
                    barcode.BARCODE_HRI_NONE: 0,
                    barcode.BARCODE_HRI_TOP: 1,
                    barcode.BARCODE_HRI_BOTTOM: 2,
                    barcode.BARCODE_HRI_BOTH: 3,}
            barcode_hri = values.get(kwargs.get('barcode_hri'))
            self._impl.device.write('\x1D\x48' + chr(barcode_hri))
github base4sistemas / pyescpos / escpos / impl / epson.py View on Github external
_VENDOR = u'Seiko-Epson Corporation'


QRCODE_ERROR_CORRECTION_MAP = {
        barcode.QRCODE_ERROR_CORRECTION_L: '\x30',  # 48d (~7%, default)
        barcode.QRCODE_ERROR_CORRECTION_M: '\x31',  # 49d (~15%)
        barcode.QRCODE_ERROR_CORRECTION_Q: '\x32',  # 50d (~25%)
        barcode.QRCODE_ERROR_CORRECTION_H: '\x33',  # 51d (~30%)
    }


QRCODE_MODULE_SIZE_MAP = {
        barcode.QRCODE_MODULE_SIZE_4: '\x04',
        barcode.QRCODE_MODULE_SIZE_5: '\x05',
        barcode.QRCODE_MODULE_SIZE_6: '\x06',
        barcode.QRCODE_MODULE_SIZE_7: '\x07',
        barcode.QRCODE_MODULE_SIZE_8: '\x08',
    }


def _get_qrcode_error_correction(**kwargs):
    return QRCODE_ERROR_CORRECTION_MAP[kwargs.get('qrcode_ecc_level',
            barcode.QRCODE_ERROR_CORRECTION_L)]


def _get_qrcode_module_size(**kwargs):
    return QRCODE_MODULE_SIZE_MAP[kwargs.get('qrcode_module_size',
            barcode.QRCODE_MODULE_SIZE_4)]


class GenericESCPOS(object):
    """The ESC/POS base class implementation.
github base4sistemas / pyescpos / escpos / impl / daruma.py View on Github external
def _barcode_impl(self, processed_data, symbology, **kwargs):
        barcode_height = _translate_barcode_height(
                kwargs.get('barcode_height', 50))

        barcode_width = _translate_barcode_width(
                kwargs.get('barcode_width', barcode.BARCODE_NORMAL_WIDTH))

        barcode_hri = _translate_barcode_hri(
                kwargs.get('barcode_hri', barcode.BARCODE_HRI_NONE))

        command = '\x1B\x62{}{}{}{}{}\x00'.format(
                chr(symbology),
                chr(barcode_width),
                chr(barcode_height),
                chr(barcode_hri),
                processed_data)

        self.device.write(command)
        time.sleep(0.25)
        response = self.device.read()
        return response
github base4sistemas / pyescpos / escpos / impl / daruma.py View on Github external
def _translate_qrcode_module_size(value):
    values = {
            barcode.QRCODE_MODULE_SIZE_4: 4,
            barcode.QRCODE_MODULE_SIZE_5: 5,
            barcode.QRCODE_MODULE_SIZE_6: 6,
            barcode.QRCODE_MODULE_SIZE_7: 7,
            barcode.QRCODE_MODULE_SIZE_8: 7, # 8 == 7
        }
    return values.get(value, None)