Giter Club home page Giter Club logo

python-escpos's Introduction

python-escpos - Python library to manipulate ESC/POS Printers

Description

Documentation Status

Python ESC/POS is a library which lets the user have access to all those printers handled by ESC/POS commands, as defined by Epson, from a Python application.

The library tries to implement the functions provided by the ESC/POS-command-set and supports sending text, images, barcodes and qr-codes to the printer.

Text can be aligned/justified and fonts can be changed by size, type and weight.

Also, this module handles some hardware functionalities like cutting paper, control characters, printer reset and similar functions.

Since supported commands differ from printer to printer the software tries to automatically apply the right settings for the printer that you set. These settings are handled by escpos-printer-db which is also used in escpos-php.

Dependencies

This library makes use of:

Documentation and Usage

The basic usage is:

from escpos.printer import Usb

""" Seiko Epson Corp. Receipt Printer (EPSON TM-T88III) """
p = Usb(0x04b8, 0x0202, 0, profile="TM-T88III")
p.text("Hello World\n")
p.image("logo.gif")
p.barcode('4006381333931', 'EAN13', 64, 2, '', '')
p.cut()

Another example based on the Network printer class:

from escpos.printer import Network

kitchen = Network("192.168.1.100") #Printer IP Address
kitchen.text("Hello World\n")
kitchen.barcode('4006381333931', 'EAN13', 64, 2, '', '')
kitchen.cut()

Another example based on the Serial printer class:

from escpos.printer import Serial

""" 9600 Baud, 8N1, Flow Control Enabled """
p = Serial(devfile='/dev/tty.usbserial',
           baudrate=9600,
           bytesize=8,
           parity='N',
           stopbits=1,
           timeout=1.00,
           dsrdtr=True)

p.text("Hello World\n")
p.qr("You can readme from your smartphone")
p.cut()

The full project-documentation is available on Read the Docs.

Contributing

This project is open for any contribution! Please see CONTRIBUTING.rst for more information.

Disclaimer

None of the vendors cited in this project agree or endorse any of the patterns or implementations. Its names are used only to maintain context.

python-escpos's People

Contributors

a-detiste avatar alejandrojaez avatar alfreedom avatar asukiaaa avatar belono avatar bougakov avatar braveheuel avatar brendanhowell avatar davisgoglin avatar dependabot[bot] avatar fmdl avatar foaly avatar gagath avatar gmarull avatar harkonenbade avatar hurta2yaisel avatar katyukha avatar krequena avatar krispy2009 avatar mashedkeyboard avatar mike42 avatar miracle2k avatar mofosyne avatar om26er avatar patkan avatar quantifiedcode-bot avatar ramonpoca avatar serpulga avatar thijstriemstra avatar zouppen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-escpos's Issues

Image Printing not working correctly

When trying to print an Image, Barcode or QR-Code, the Printer only prints a 
lot of Characters.

Printer Model: Epson TM-T88III

I'm on a Raspberry Pi - Model B
OS: Debian GNU/Linux 7.0 (wheezy) (Raspbian “wheezy”)

Python:
- Python 2.7.3
- Python Imaging 1.1.7

Original issue reported on code.google.com by [email protected] on 8 Apr 2013 at 7:32

Added Printing Density support

Hi,

I am working with a Custom thermo-direct printer and need to set the print 
density of my printer.

I added this lines to constants.py 

# Printing Density
PD_n50          = '\x1d\x7c\x00'     # Printing Density -50%
PD_n37          = '\x1d\x7c\x01'     # Printing Density -37.5%
PD_n25          = '\x1d\x7c\x02'     # Printing Density -25%
PD_n12          = '\x1d\x7c\x03'     # Printing Density -12.5%
PD_0            = '\x1d\x7c\x04'     # Printing Density  0%
PD_p50          = '\x1d\x7c\x08'     # Printing Density +50%
PD_p37          = '\x1d\x7c\x07'     # Printing Density +37.5%
PD_p25          = '\x1d\x7c\x06'     # Printing Density +25%
PD_p12          = '\x1d\x7c\x05'     # Printing Density +12.5%

and I changed the escpos.py adding this lines.

def printdens(self, dens):
        """ Set Printer Density """
        if dens == 0:
            self._raw(PD_n50)
        elif dens == 1:
            self._raw(PD_n37)
        elif dens == 2:
            self._raw(PD_n25)
        elif dens == 3:
            self._raw(PD_n12)
        elif dens == 4:
            self._raw(PD_0)
        elif dens == 5:
            self._raw(PD_p12)
        elif dens == 6:
            self._raw(PD_p25)
        elif dens == 7:
            self._raw(PD_p37)
        elif dens == 8:
            self._raw(PD_p50)
        else:# DEFAULT: DOES NOTHING
            pass

Everything works fine, maybe you can add this feature to your next release.

Thank's

Thomas



Original issue reported on code.google.com by [email protected] on 9 Jan 2014 at 1:10

The qr() method must whitespace-pad above and below the QR code

The white border around a QR code is a non-optional part of the registration 
marking system used by scanners to recognize the code.

In order to get the libdecodeqr-simpletest example program to recognize the QR 
code printed by the example code at 
https://code.google.com/p/python-escpos/wiki/Usage and decode it, I had to:

1. Scan it
2. Open it in GIMP
3. Use the eraser tool to replace part of the logo.gif contents above and 
barcode below with white.

While I understand taking the full 13 digits of an EAN13 barcode as input since 
barcode readers and ISBN-13 databases treat the checksum digit as part of the 
data, there is no similar reason to let users generate broken QR codes.

Original issue reported on code.google.com by [email protected] on 20 May 2014 at 1:59

Need more params in printer.Serial() constructor

Sending more params to printer.Serial() constructor is needed to fully support 
every serial printer model, so one could configure parity, stopbits, xonxoff or 
dsrdtr according to the printer DIP switch configuration.

For example, my TM-H6000 needs this params to work properly:

self.device = serial.Serial(port=self.devfile, baudrate=self.baudrate, 
bytesize=self.bytesize, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_ONE, 
timeout=self.timeout, xonxoff=1, dsrdtr=False)

which is a non standard python-escpos configuration, and can't be set or 
modified under run time.

Original issue reported on code.google.com by [email protected] on 11 Sep 2013 at 8:24

how can I use this on openwrt ?

root@OpenWrt:/mnt/sda5/esc# opkg list | grep py
pyserial - 2.4-1
python - 2.7.3-2
python-imaging-library - 1.1.7-2
python-mini - 2.7.3-2
python-openssl - 2.7.3-2
pyusb - 0.4.2-1
root@OpenWrt:/mnt/sda5/esc# ls /usr/lib/python2.7/site-packages/
PIL                               easy_install.py                   
pyserial-2.4-py2.7.egg-info       setuptools                        usb
PIL.pth                           escpos                            
pyusb-0.4.2-py2.7.egg-info        setuptools-0.6c11-py2.7.egg-info  usb.so
README                            escpos-2.7-py2.7.egg-info         
pyusb-1.0.0a2-py2.7.egg-info      setuptools.pth
distribute-0.6.21-py2.7.egg-info  pkg_resources.py                  
qrcode-4.0.4.post-py2.7.egg       site.py
easy-install.pth                  pkg_resources.pyc                 serial      
                      six-1.4.1-py2.7.egg

Bus 001 Device 003: ID 04b8:0e03 Seiko Epson Corp.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x04b8 Seiko Epson Corp.
  idProduct          0x0e03
  bcdDevice            1.00
  iManufacturer           1 EPSON
  iProduct                2 TM-T20
  iSerial                 3 405540blablablabla0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           32
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xc0
      Self Powered
    MaxPower                2mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         7 Printer
      bInterfaceSubClass      1 Printer
      bInterfaceProtocol      2 Bidirectional
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Status:     0x0001
  Self Powered
root@OpenWrt:/mnt/sda5/esc# python esc.py
Traceback (most recent call last):
  File "esc.py", line 3, in <module>
    Epson = printer.Usb(0x04b8,0x0e03)
  File "/usr/lib/python2.7/site-packages/escpos/printer.py", line 34, in __init__
    self.open()
  File "/usr/lib/python2.7/site-packages/escpos/printer.py", line 39, in open
    self.device = usb.core.find(idVendor=self.idVendor, idProduct=self.idProduct)
  File "/usr/lib/python2.7/site-packages/usb/core.py", line 846, in find
    raise ValueError('No backend available')
ValueError: No backend available

Original issue reported on code.google.com by [email protected] on 30 Dec 2013 at 9:21

Printing - Operation timed out error

What steps will reproduce the problem?
1. My python app uses a USB thermal printer (TM-T20) to print a long text. 
2. I put the long stream of text (12k characters) on the Epson.text("long 
text..") method. 
3. The appl prints some of the text and then the printing stops and produce an 
error "usb.core.USBError: [Errno 110] Operation timed out" and then exits the 
app.
4. I even tried to split the text into 6k characters for each Epson.text call 
but still getting the timeout on the 2nd Epson.text call.

What is the expected output? What do you see instead?
- Expected result is to print the completed text without error. Instead I'm 
getting a timeout error. "usb.core.USBError: [Errno 110] Operation timed out" 

What version of the product are you using? On what operating system?
-Raspbian OS, Python 2.7 and python-escpos-1.0-1 

Please provide any additional information below.
Below is the sample code.

#!/usr/bin/python
from escpos import *
    """ Seiko Epson Corp. Receipt Printer Definitions (EPSON TM-T20) """
    Epson = printer.Usb(0x04b8,0x0e03)
    Epson.set(font='B',type='NORMAL',width=1,height=1)
    Epson.control("FF")
    Epson.text("some very very long receipt text...")   #this would be a text with 12K characters
    Epson.cut()

==========================================
Error received

Traceback (most recent call last):
  File "sertest.py", line 40, in <module>
     File "sertest.py", line 11, 
    Epson.text(printdata)
  File "/usr/local/lib/python2.7/dist-packages/escpos/escpos.py", line 177, in text
    self._raw(txt)
  File "/usr/local/lib/python2.7/dist-packages/escpos/printer.py", line 58, in _raw
    self.device.write(self.out_ep, msg, self.interface)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 619, in write
    self.__get_timeout(timeout)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py", line 532, in bulk_write
    timeout)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py", line 628, in __write
    timeout))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py", line 403, in _check
    raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno 110] Operation timed out

Original issue reported on code.google.com by [email protected] on 26 Nov 2013 at 7:33

Raspberry thermal Printer GP80 like epson TM-T80

What steps will reproduce the problem?
1.i was initial my print with: 
gp80=printer.Usb(0x0FE6,0x811E,0,0x82,0x02)
gp80.text("test print 12345")

2. no error, but printer no action(do nothing)
3. then i try to cut: gp80.cut() 
it's ok, printer cut the paper


What is the expected output? What do you see instead?
my print china product: 
http://www.gainscha.com.cn/products_show.asp?lan=zh-en&skin=2&newsid=141573127 
 i'm install driver from this website in raspbian linux with cup 
testprint result : stopped "/usr/lib/cups/filter/rastertogpt failed"

What version of the product are you using? On what operating system?
raspberry debian 2013

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 8 Mar 2014 at 2:40

TXT_ALIGN_CT referenced but not defined in PyPI-provided v1.0.6

What steps will reproduce the problem?
1. sudo pip install python-escpos
2. Run the test code from https://code.google.com/p/python-escpos/wiki/Usage

The test code successfully prints the barcode when using the archive 
downloadable from Google Code but, since that's too old to have QR Code 
support, I switched to the pip-provided version instead.

However, the pip-provided version errors out because the TXT_ALIGN_CT constant 
isn't defined:

Traceback (most recent call last):
  File "test_escpos.py", line 37, in <module>
    test()
  File "test_escpos.py", line 16, in test
    Epson.barcode('1324354657687', 'EAN13', 64, 2, '', '')
  File "/usr/local/lib/python2.7/dist-packages/escpos/escpos.py", line 209, in barcode
    self._raw(TXT_ALIGN_CT)
NameError: global name 'TXT_ALIGN_CT' is not defined

Original issue reported on code.google.com by [email protected] on 20 May 2014 at 3:13

Partial cut

Also i could not find info on how to do partial cut

Epson.cut() for full cut is easy... but how do i do a partial?

my printer is a Epson TM-T88II

Original issue reported on code.google.com by [email protected] on 15 Mar 2015 at 4:03

QR slow

Hi, i'm using this library for raspberry and everything works fine.

I've got a "problem" when trying to print QR codes with an url content.
The problem is that is too slow, like 10 or 20 seconds to process it, and all 
the system is waiting for finish it. I know that i can use background command 
but i need to wait until it finish.

Is this normal? Also is too slow printing images.
I've used all the library packages on the install guide.

Thanks!

PD: Sorry for my English!


Original issue reported on code.google.com by [email protected] on 2 Mar 2014 at 12:07

Broken Link

The link to the project's homepage has an error.
screenshot from 2015-05-30 20 14 10

align left and right on the same line

What steps will reproduce the problem?
1. use Epson TM-T20
2. execute the following code
3.

What is the expected output? What do you see instead?
I would like to format a line to begin on the left with some words ("article" 
in my example) and then align on the right to write the price (15.00 € here)

What version of the product are you using? On what operating system?
python-escpos 1.0-1 on ubuntu 13.10

Please provide any additional information below.

code :
Epson.set("LEFT", "A", "", 1, 1)
Epson.text("Article 1")
Epson.set("RIGHT", "A", "", 1, 1)
Epson.text("15.00 \xd5")
Epson.text("\n")

Original issue reported on code.google.com by [email protected] on 15 May 2014 at 10:29

German umlaut not printed properly (with inelegant solution)

Hi,

first: Thank you for your effort. I have used another library before which I 
fitted a little pro my Epson but which lacked image support.
Your library has given me the great opportunity to print images and also qr 
code (cool bonus) without fumbleing myself hour per hour.

Back then i've written a little workaround for the usual umlaut-problem.

It is not very elegant but it does as needed:

    def Umlaut_toASCII(self, s):
        s=s.replace('ä', chr(132))
        s=s.replace('Ä', chr(142))
        s=s.replace('ö', chr(148))
        s=s.replace('Ö', chr(153))
        s=s.replace('ü', chr(129))
        s=s.replace('Ü', chr(154))
        s=s.replace('ß', chr(225))
        return s

    def text(self, txt):
        """ Print alpha-numeric text """
        if txt:
            self._raw(self.Umlaut_toASCII(txt))
        else:
            raise TextError()

please note that you have to set enconding in the second line for this:
# -*- coding: utf-8 -*-

Original issue reported on code.google.com by [email protected] on 8 Nov 2014 at 1:08

needs a method to set tab positions

What steps will reproduce the problem?
try and do a horizontal tab

What is the expected output? What do you see instead?
no output

What version of the product are you using? On what operating system?


Please provide any additional information below.

the horizontal and I think vertical tabs do nothing (or might do a line feed) 
until the tab positions have been set with ESC D <list of columns> null

Original issue reported on code.google.com by [email protected] on 15 Nov 2012 at 10:40

Star tsp100 printer (common)

I have a star tsp100 printer and drawer. I've attempted to modify things a bit 
to attempt a drawer kick to start but i couldn't get it to work correctly. I'd 
love to im or email about the issues. I know there are a lot of these 
printers/drawers out there.

Original issue reported on code.google.com by [email protected] on 30 Jan 2011 at 4:18

Barcode width / height not working

What steps will reproduce the problem?
1. Print barcode type UPC-A
2. Put any value in for width and height
3. Barcode always same size

Original issue reported on code.google.com by [email protected] on 15 Apr 2014 at 8:21

Spanish characters

I'm pretty sure this is something you already have solved because you are 
Spanish speaker too, at least that's what I guess for your name.

How do you do for send to print spanish characters like: á, é í, ó, ú, ñ?

Thanks a lot in advance

Original issue reported on code.google.com by [email protected] on 16 Aug 2013 at 4:55

Epson TM-T88IV printing garbage

I connected my Epson TM-T88IV thermal receipt printer to my Raspberry Pi via 
serial connection. The printer has a RS232 port, from which I'm using pins no. 
2, 3 and 7, which are used for transmit, read and ground signals. Those pins 
are connected to corresponding Raspberry Pi pins while transmit and read are 
crossed.

I followed the set-up and usage tutorial step by step, but whenever I try to 
print some kind of data (e.g. Hello world!) then the printer prints garbage. At 
first it printed random garbage text, but when I set up the DIP switches (DSW1: 
all pins except 7 are off; DSW2: all pins are off) and changed the settings in 
the code, it keeps printing me the same garbage text every time. For example, 
the text 'Hello world!' prints as 'S ??::'. Whenever I try printing a single 
letter, the printer wouldn't print anything at all.

I think that the problem lays somewhere between the printer and Raspberry Pi 
settings, but could anyone help me get closer to the solution?


Original issue reported on code.google.com by [email protected] on 6 Feb 2015 at 11:58

Image printing not working on Epson TM U220

What steps will reproduce the problem?
1. Connect the printer to the USB bus. The printer is an Epson TM U220
2. Initialize the printer via Epson = printer.Usb instruction 
3. Execute a Epson.image instruction on any kind of image file, format or size

What is the expected output? What do you see instead?

The image should be printed in paper. A large series of ASCII chars are printed 
instead.

What version of the product are you using? On what operating system?


I am using it on Ubuntu 12.04. Text printing works just fine. I have tried 
different image formats, sizes, etc and the error is always the same. 

Original issue reported on code.google.com by [email protected] on 19 Feb 2015 at 10:17

Thai font

How i can print thai character ?

here is my code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from escpos import *

reload(sys)
sys.setdefaultencoding('UTF8')
str_th = "ลองตัวอักษรไทย"

Espon = printer.Usb(0x04b8,0x0202)
# Espon.set(codepage='cp874',size='2x')
Espon.text(str_th)
Espon.cut()


and i see in file "constants.py" was comment line

  # 'TIS_14' : 21,
  # 'TIS_17' : 22,
  # 'TIS_11' : 23,


Original issue reported on code.google.com by [email protected] on 30 Jul 2014 at 10:08

Spacing in the image print

When I print a picture (eg qrcode) I have lines which are in the picture.
img_20150527_111104

With official driver on mac, no problem (pdf):
img_20150527_111131

A solution ?

Thanks

USBError: Access denied (insufficient permissions)

What steps will reproduce the problem?
1. New to using raspberry pi and escpos
2. Trying to run the sample readme code
3. Getting the following error "USBError: Access denied (insufficient 
permissions)

What is the expected output? What do you see instead?
I assume I need to add additional permissions to the dialout group....have had 
trouble finding out how. I'll continue to dig, but any help would be amazing :)




Original issue reported on code.google.com by [email protected] on 23 Mar 2014 at 12:56

Epson TM-88IV - set() bold/underline etc. not working

So far the only parameter handled properly by set() seems to be the alignment 
and width/height
Bold, font type, underline are not working. 

If commands are sent explicitly via text(..) things work. So the values stored 
in constants.py are correct for this printer model.

System:
Raspberry Pi, Raspbian
Epson TM-88IV (M129H) printer, LAN
Python 2.7.3
escpos: 1.0.1
qrcode: 2.7

Reproduce:
-----------SNIP----------------
#!/usr/bin/python

from escpos import *
Epson = printer.Network("xxx.xxx.xxx.xxx")

# WORKING
Epson.set('left', 'a', 'b', 1, 1)
Epson.text('Font A 1 1\n')
Epson.text('left aligned\n')

# NOT BOLD
Epson.set('right', 'a', 'b', 1, 1)
Epson.text('Font A b 1 1\n')
Epson.text('right aligned? bold?\n')

# NOT UNDERLINED
Epson.set('right', 'a', 'u', 1, 1)
Epson.text('Font A u 1 1\n')
Epson.text('underlined?\n')

# back to left aligned
Epson.set('left', 'a', 'normal', 1, 1)

# WORKS
# send command for bold directly
Epson.text("\x1b\x45\x01")
Epson.text("explicit bold\n")
Epson.text("\x1b\x45\x00")

Epson.text("This should be normal again.\n\n")

# mimic escpos.py behaviour by sending bold and underline off

# WORKS
Epson.text("\x1b\x45\x01")
Epson.text("\x1b\x2d\x00")
Epson.text("explicit bold on and underline off\n")
Epson.text("\x1b\x45\x00")
-------------SNAP--------------

I attached a scan from the original printout of above file.

Original issue reported on code.google.com by [email protected] on 24 Jun 2013 at 3:36

Attachments:

ImportError: No module named Image

I'm getting an import error after following the instructions for the Raspberry 
Pi.  It's a fresh install of the latest Raspbian image, and I'm using an Epson 
TM-T20 over USB.  I installed the dependencies as per the instructions, and 
obtained the vendor and product ID.

This is my test code:

from escpos import *
Epson = printer.Usb(0x04b8,0x0e03)
Epson.text("Hello World\n")
Epson.cut()

This is the error message:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from escpos import *
  File "/usr/local/lib/python2.7/dist-packages/escpos/escpos.py", line 9, in <module>
    import Image
ImportError: No module named Image

Can anyone help?

Original issue reported on code.google.com by [email protected] on 11 Oct 2013 at 5:15

last line of escpos.py is wrong

What steps will reproduce the problem?
try and do a vertical tab


What is the expected output? What do you see instead?

error about delf

What version of the product are you using? On what operating system?


Please provide any additional information below.
line 255
            delf._raw(CTL_VT)
should be
            self._raw(CTL_VT)

Original issue reported on code.google.com by [email protected] on 15 Nov 2012 at 10:36

Ethernet printer support

Hi,

Great work!
Do you plan support ethernet printers?

I'd like to use your code for printing to ethernet esc/pos printer. I don't 
know python at all. Please give advice which library to use instead of usb?

I will report results to you.

Thanks in advance.

Original issue reported on code.google.com by [email protected] on 16 Jun 2011 at 4:35

Thai codepage error

os:Raspberry Pi

I want to print thai font this is my code

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from escpos import *
import qrcode

Epson = printer.Usb(0x0519,0x0001)
s = u'ตัวอักษรไทย'
Epson.text("Hello World\n")
ss=s.encode('cp874')
Epson.text(ss)
Epson.cut()


but thai letter 'ตัวอักษรไทย' it came out like a added 
picture  
how can I solve it??

Original issue reported on code.google.com by [email protected] on 3 Nov 2014 at 10:55

Attachments:

Configuration

Hi Manuel,

I am trying to get this going using the code downloaded from here yesterday.

Output of lsusb is:

# lsusb
Bus 001 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0001
Bus 001 Device 002: ID 0c45:62e0
Bus 001 Device 003: ID 05e3:070e
Bus 002 Device 002: ID 067b:2305

it is the last device that is the printer as it disappears when it is turned 
off!

This is a BusyBox lsusb and HardInfo says it is on Bus 2 level 1
I also compiled proper lsusb and got the following info relating to the printer:

Bus 002 Device 002: ID 067b:2305 Prolific Technology Inc.
    Intf 2-1:1.0 ((null))

Following the README to get the interface and endpoint - the output of the 
command:

# ./lsusb -vvv -d 067b:2305 |grep iInterface
# 
is nothing at all!

similarly:

#lsusb -vvv -d 067b:2305 | grep bEndpointAddress | grep OUT  
# 

I am running the example script:

#!/usr/bin/python

from escpos import *

Epson = escpos.Escpos(0x67b,0x2305,2)
Epson.text("Hello World")
Epson.barcode
Epson.barcode('1324354657687','EAN13',64,2,'','')
Epson.cut()

with python 2.7.2 and I get the following - I have tried with a number of 
permutations of:
Epson = escpos.Escpos(0x67b,0x2305,0)
Epson = escpos.Escpos(0x67b,0x2305,1)

# ./test.py
[Errno 22] Invalid parameter
Traceback (most recent call last):
  File "./test.py", line 6, in <module>
    Epson.text("Hello World")
  File "/initrd/mnt/dev_save/my-applications/POSLogic/escpos/escpos.py", line 201, in text
    self._raw(txt)
  File "/initrd/mnt/dev_save/my-applications/POSLogic/escpos/escpos.py", line 60, in _raw
    self.handle.bulkWrite(self.out_ep, msg, 1000)
  File "/usr/lib/python2.6/site-packages/usb/legacy.py", line 148, in bulkWrite
    return self.dev.write(endpoint, buffer, self.__claimed_interface, timeout)
  File "/usr/lib/python2.6/site-packages/usb/core.py", line 617, in write
    intf.bInterfaceNumber,
AttributeError: 'NoneType' object has no attribute 'bInterfaceNumber'
'NoneType' object is not iterable

On what operating system?

I am on racy puppy linux with kernel 3.02

Appreciate any pointers?

Thanks


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 28 Apr 2012 at 3:27

Generic.text("Hello World") File "/usr/local/lib/python2.7/dist-packages/escpos/escpos.py", line 264, in text self._raw(text)

Dear community;

I use Rasbian, I got the phoenix printer 
(http://pyramidacceptors.com/phoenix-printer/) from PTI. I use Rasbian as OS. I 
attach a dump of the details of printer. I used following python code:

from escpos import *
Epson = printer.Usb(0x2504,0x0300)
Epson.text("Hello World")
Epson.cut()

Running this code as root results:

  File "gpio.py", line 5, in <module>
    Epson.text("Hello World")
  File "/usr/local/lib/python2.7/dist-packages/escpos/escpos.py", line 264, in text
    self._raw(text)
  File "/usr/local/lib/python2.7/dist-packages/escpos/printer.py", line 58, in _raw
    self.device.write(self.out_ep, msg, self.interface)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 625, in write
    fn = fn_map[self._ctx.get_endpoint_type(self, endpoint, intf)]
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 180, in get_endpoint_type
    etype = util.endpoint_type(e.bmAttributes)
AttributeError: 'NoneType' object has no attribute 'bmAttributes'


All the best;

Original issue reported on code.google.com by [email protected] on 18 Jul 2014 at 2:52

set(font="B") doesn't seem to work on TM81.

Hi

I am using a Epson TM81 on Ubuntu 12.10.  With the latest python-escpos over 
usb.  Everything I have tried so far works with the exception of selecting font 
B.  When I use print.set(font="B") I do not see any change in the font.

The set font code is sending ESC M '\x1b\x4d\x01' which appears to be correct 
as far as I can see. 

I found that I could select font B, when using the the escape sequence ESC ! n 
-  Select print mode (s) which based on the docs would be "\x1b\x21\x01" and 
then everything works fine. 

I have not been able to find any docs specific to TM81 which defines the ESC M, 
 only docs that support TM88 that define ESC ! (n) and ESC M (n).  


Original issue reported on code.google.com by [email protected] on 15 Apr 2013 at 7:45

Clarify license

Hi,

we are using escpos in a cashdesk application that will go open source soon. I noticed that your COPYING file states "GPL3", while escpos.py says "GPL", which would mean the antique GPL 1. As different license version cannot be mixed, this is a problem for us. Could you clarify this to say "GPL 3", or preferably "GPL3 or any later version"?

Thanks for your work,
Max

Can't print

Hello,

I just found your python library today but I have not had success getting it to 
work.  Any help would be appreciated!

Thanks,
Jack

I am getting this message for test.py:

dell@Dell:~/python-escpos-a1ff2d1740ad/escpos$ python test.py
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    Epson = printer.Usb(0x04b8,0x0202)
NameError: name 'printer' is not defined


The printer is an Epson TM-T88II connected with USB.

lsusb
Bus 003 Device 002: ID 04b8:0202 Seiko Epson Corp. Receipt Printer M129C

lsusb -vvv -d 04b8:0202 | grep iInterface
      iInterface              0
lsusb -vvv -d 04b8:0202 | grep bEndpointAddress | grep OUT
        bEndpointAddress     0x01  EP 1 OUT

lsusb -vvv -d 04b8:0202
...
idVendor           0x04b8 Seiko Epson Corp.
idProduct          0x0202 Receipt Printer M129C

OS Ubuntu 12.04.3 LTS
Linux Dell 3.8.0-39-generic #58~precise1-Ubuntu SMP Fri May 2 21:33:17 UTC 2014 
i686 i686 i386 GNU/Linux

python-serial 2.5-2.1build1
pyusb-1.0.0b1
python-qrcode
python-escpos-a1ff2d1740ad




test.py

from escpos import *

Epson = printer.Usb(0x04b8,0x0202)
# Print text
Epson.text("Hello World\n")
# Print image
Epson.image("logo.gif")
# Print QR Code
Epson.qr("You can readme from your smartphone")
# Print barcode
Epson.barcode('1324354657687','EAN13',64,2,'','')
# Cut paper
Epson.cut()


Original issue reported on code.google.com by [email protected] on 22 May 2014 at 10:16

Corrections for direct printer firmware typeface flags

What steps will reproduce the problem?

1. Epson.set('center','A','NORMAL',2,2)

   ( The typeface is tall and not wide;
     double width and height is a single 0x30 flag,
     not 0x10 and 0x20 in sequence;
     0x20 ends up cancelling 0x10. )

2. Epson.set('center','U2','NORMAL',2,2)

   ( a stale constant for turning off Italic remains;
     this is not defined in constants.py; therefore,
     delete this line )



What is the expected output? What do you see instead?

1. For text that should be quad area, I see
   Text that is tall, and not wide

2. For normal weight with strong underline,
   I see A NameError:

>>> Epson.set('center','A','U2',2,2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/escpos/escpos.py", line 206, in set
    self._raw(TXT_ITALIC_OFF)
NameError: global name 'TXT_ITALIC_OFF' is not defined



What version of the product are you using? On what operating system?

$ hg summary
parent: 12:849dabb63ce0 tip
 Added syntax to have print working on windows
branch: default
commit: 2 modified, 5 unknown
update: (current)

$ uname -imrs 
FreeBSD 9.2-RELEASE i386 GENERIC



Please provide any additional information below.

  diff attached in hg-diff-escpos.txt;

  constants.py:
    1. I have introduced a suggested fix for quad area characters,
    in the form of a new constant, "TXT_4SQUARE".

  escpos.py:
    1. For quad-area characters, reset to normal first,
    then send only one flag to activate double width and height.

    2. The deprecated constant, "TXT_ITALIC_OFF", is removed.

This was verified on an Epson TM-H6000, IEE-1284 (parallel)
  Epson = printer.File("/dev/lpt0")


Thank you for this library. I look forward to extending it
if I am able to.

Thanks as well to the developers of Mercurial;
an R.C.S that works, just as the developers intended.

Original issue reported on code.google.com by [email protected] on 10 Dec 2013 at 4:03

Attachments:

Random characters printed

Hi everyone,

I'm trying to print some text with an Epson TM-H6000iii on my raspberry pi.
The problem is that I only have a sequence of "Ç?Ç?Ç°" no matters what I 
write.

Here is my code :

#!/usr/bin/env python
from escpos import *

#Bus 001 Device 006: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

Epson = printer.Serial("/dev/ttyUSB0",9600,8,2)
Epson.text("Hello world !!!")
Epson.text("0920192")
Epson.cut()

As you can see I'm using a serial adapter.

Original issue reported on code.google.com by [email protected] on 12 Oct 2013 at 1:33

trouble printing variables..... i'n NOOB

Hi

i have troubles printing variables with the library.... i used the example code 
to confirm that printer works... now i have this line of code but i get an 
error:

Epson.text(text) 

my variable is called text...

i have tried to add single and double quotes.. ' ' and " "

the error is:

    raise TextError()
TextError: Text string must be supplied to the text() method

what have the "NOOB" done wrong?


Original issue reported on code.google.com by [email protected] on 20 Feb 2014 at 8:18

"this constructor takes no arguments" error

I am trying to send data to my printer, but i keep getting this error:

Traceback (most recent call last):
  File "./printtest.py", line 3, in <module>
    Epson = escpos.Escpos(0x4348,0x5584)
TypeError: this constructor takes no arguments

My test file contains

from escpos import *

Epson = escpos.Escpos(0x4348,0x5584)
Epson.text("Hello World")
Epson.cut()

My printer is Bus 001 Device 004: ID 4348:5584 WinChipHead CH34x printer 
adapter cable

root@raspberrypi:/home/pi# lsusb -vvv -d 4348:5584 | grep iInterface
      iInterface              0 

root@raspberrypi:/home/pi# lsusb -vvv -d 4348:5584 | grep bEndpointAddress | 
grep OUT
        bEndpointAddress     0x02  EP 2 OUT

i tried Epson = escpos.Escpos(0x4348,0x5584), Epson = 
escpos.Escpos(0x4348,0x5584,0) Epson = escpos.Escpos(0x4348,0x5584, 0x02), 
Epson = escpos.Escpos(0x4348,0x5584,0,0x02) but no luck.

Any idea why this goes wrong? 

Kind regards, John

Original issue reported on code.google.com by [email protected] on 18 Mar 2013 at 7:46

Python 3.3.2 64bit Windows installation errors

What steps will reproduce the problem?
1. Install Python 3.3.2 64bit on Windows machine
2. py setup.py build
3. py setup.py install

What is the expected output? What do you see instead?
Some syntax error because print in Python 3 becomes a function, so escpos.py 
has to been edited (see attachments). In printer.py, line 34, there is an 
inconsistent use of tabs and spaces in indentation.

What version of the product are you using? On what operating system?
python-escpos-1.0-1, Python 3.3.2 64bit on Windows machine

Please provide any additional information below.
I've attached modified copies of escpos.py and printer.py

Original issue reported on code.google.com by [email protected] on 26 May 2013 at 2:29

Attachments:

Enhancement: define a 12x24 Type-A font, for hexadecimal

This is alpha quality code,
 which will need some consideration
 as to how it will be integrated,
 but I promise it is worth it !

On decent Epson printers, it should be possible to redefine the font, for the 
low-order 7-bit ASCII part of the character tables.

The demonstration script attached will change one of the Type-A fonts on the 
thermal printer.

Epson printers have at least two fonts. I picked type A, because of its evenly 
sized 12x24 character cells, which are easy to redefine as you will see.



Are you the kind of person that is bothered by base 10, but are not too 
enthused about alphanumeric hexadecimal?

I am; therefore, the first characters I substituted were:

 0-9, a-f.

I call my font, DashNibs;
 that is,
 it hangs on a dash,
 and each digit is one Nibble;
 i.e. formally known as "DashNibbles."



Try this example command on your LPT connected printer:

./demonstrate_glyphing.py 6 R 4

(my tm-h6000 on lpt template)
(roll paper, not slip)
(example 4; quad area ASCII table)



The USB port selection needs to be hacked for Linux. It should be possible to 
just use the default USB printer object in python-escpos. What you will see in 
my code, is a work-around for the USB Epson interface on FreeBSD systems.

LPT is easier; it will work, by renaming from lpt0 to lp0.

I have tested this successfully on the Epson TM-H5000II and Epson TM-H6000. I 
will pitch in a cleaner, portable version, when I have time later.

Original issue reported on code.google.com by [email protected] on 15 Jun 2014 at 12:06

Attachments:

Barcode would not print reliably on TM81

Just couldn't get barcodes to print reliably or completely on the TM81.  
Looking at the docs 
http://nicholas.piasecki.name/blog/wp-content/uploads/2009/12/ESC-POS-Command-Gu
ide.pdf  printing a barcode 
to print 

1. ASCII GS k md1...dk NUL 
 Hex. 1D 6B md1...dk NUL 
 Decimal 29 107 md1...dk NUL 
2. ASCII GS k m nd1...dk 
 Hex. 1D 6B m nd1...dk 
 Decimal 29 107 m nd1...dk

1. 0 ≤ m ≤ 6 The definition region of k and d differ according to the bar 
code type. 
 2. 65 ≤ m ≤ 73 The definition region of n and d differ according to the bar code type.

Which boils down to the character string being printed if you use option 1, 
needs a NULL terminator.  Option 2 the leading byte says how long the string 
will be.

I opted for option 1, and include NUL  '\x00' at the end of the string.


Original issue reported on code.google.com by [email protected] on 31 May 2013 at 4:13

New to printing

I'll preface this by saying that I'm quite new at this and I do not think there 
is an issue with the module. Any help would be amazing! :)

I've isolate the error to the escpos.text() function. Here is my sample code: 

from escpos import *
""" Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """


Epson = printer.Usb(0x04b8,0x0202)

print("print before text")
Epson.text("Hello World")
print("Print after text")

Epson.cut()


In my console, I see that "print before text" is printing out, but "print after 
text" is not.  Would you happen to have a sample application I might be able to 
try out? or any recommendations?

I am using an Epson TM-T88iv. Here is the output from lsusb:

Bus 001 Device 043: ID 04b8:0202 Seiko Epson Corp. Receipt Printer M129C

Thanks!
Joseph

Original issue reported on code.google.com by [email protected] on 23 Mar 2014 at 2:30

can't initialize printer

I get the error below when trying to initialize the printer with the vendor and product IDs

from escpos import *
epson = printer.Usb(0x0416,0x5011)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/escpos/printer.py", line 34, in init
self.open()
File "/usr/local/lib/python2.7/dist-packages/escpos/printer.py", line 43, in open
if self.device.is_kernel_driver_active(0):
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 721, in is_kernel_driver_active
self._ctx.get_interface(self, interface).bInterfaceNumber)
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 150, in get_interface
cfg = self.get_active_configuration(device)
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 165, in get_active_configuration
bConfigurationValue=self.backend.get_configuration(self.handle)
File "/usr/local/lib/python2.7/dist-packages/usb/util.py", line 176, in find_descriptor
return _interop._next(desc_iter(k, v))
File "/usr/local/lib/python2.7/dist-packages/usb/_interop.py", line 60, in _next
return next(iter)
File "/usr/local/lib/python2.7/dist-packages/usb/util.py", line 157, in desc_iter
for d in desc:
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 742, in iter
yield Configuration(self, i)
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 418, in init
configuration
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 711, in get_configuration_descriptor
config, byref(cfg)))
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 571, in _check
raise USBError(_str_error[ret], ret, _libusb_errno[ret])
KeyError: -101

Thanks a lot

How to print QR codes next to each other

looked everywhere and googled it...
nowhere i can find easy to understand info on how to print QR codes next to 
each other


right now i have this code:

#           if havePrinter: Epson.text("Tilbereder\n")
#           if havePrinter: 
Epson.qr('http://print.xn--pizzalg-v1a.dk/arduino4.php?sc=****&s=cooking&o='+str
(order))

#           if havePrinter: Epson.text("P\x7D Vej\n")
#           if havePrinter: 
Epson.qr('http://print.xn--pizzalg-v1a.dk/arduino4.php?sc=****&s=onway&o='+str(o
rder))

#           if havePrinter: Epson.text("Leveret\n")
#           if havePrinter: 
Epson.qr('http://print.xn--pizzalg-v1a.dk/arduino4.php?sc=****&s=delivered&o='+s
tr(order))

# is because i have disabled the codes for now as the print is to long if 
printed under each other

Original issue reported on code.google.com by [email protected] on 15 Mar 2015 at 4:02

T20II 003

Hi,

I am using the TM20II 003 Version and i cannot find the printer in lsusb. Everything worked fine with the TM20II 002. Can someone help me with this issue?

Thanks,
H1GHWAvE

File "/usr/local/lib/python2.7/dist-packages/escpos/printer.py", line 34, in init self.open()

Hi, I'm running the test code after followed the instructions and getting this 
error:

Traceback (most recent call last):

File "test1.py", line 2, in <module>
Epson = printer.Usb(0x04b8,0x0e03)
File "/usr/local/lib/python2.7/dist-packages/escpos/printer.py", line 34, in 
init
self.open()
File "/usr/local/lib/python2.7/dist-packages/escpos/printer.py", line 43, in 
open
if self.device.is_kernel_driver_active(0):
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 992, in 
is_kernel_driver_active
interface)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/init.py", line 363, in 
is_kernel_driver_active
not_implemented(self.is_kernel_driver_active)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/init.py", line 79, in 
not_implemented
raise NotImplementedError?(func.name)
NotImplementedError?: is_kernel_driver_active

Original issue reported on code.google.com by yuvidesign on 14 Oct 2014 at 4:07

CD_KICK (cash drawer code appears wrong).

Hi

I couldn't get the cash drawer opening when using a TM81.  Based on this 
documentation 
http://nicholas.piasecki.name/blog/wp-content/uploads/2009/12/ESC-POS-Command-Gu
ide.pdf  

a pulse duration is required which is not included in the current code.

The docs say ASCII DLE DC4 n m t 

This outputs a signal specified by t to the connector pin specified by m. 
 m = 0: #2 Pin of the drawer kick connector 
 m = 1: #5 Pin of the drawer kick connector 
 On time is set to t x 100 msec; Off time is set to t x 100 msec


The current code has 

CD_KICK_2 = '\x1b\x70\x00'     # Sends a pulse to pin 2 [] 
CD_KICK_5 = '\x1b\x70\x01'     # Sends a pulse to pin 5 [] 

Which didn't work.

I changed the constants to 

CD_KICK_2 = '\x1b\x70\x00\x50\x50'      
CD_KICK_5 = '\x1b\x70\x01\x50\x50'     

Which works reliably on the TM81

Original issue reported on code.google.com by [email protected] on 31 May 2013 at 3:12

Print image limited to 255px height

Hello there,

I am trying to print images that are bigger than 255px in height but it throws 
ImageSizeError(). Is there any reason to limit the image size in hieght ? 

Thanks



Original issue reported on code.google.com by [email protected] on 23 May 2014 at 6:06

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.