Friday, April 1, 2011

Epson POS TM T81

This is my second pos printer device that I have worked with. The previous one was dot matrix, RS-232, and has no independent power supply adaptor, so it depends on the PC which has that particular of power outlet. Not so good. Terrible, actually.
Epson POS TM T81 is using usb adapter and has its own power supply adapter. So, it is more portable.

The issue is how to communicate with. Previously, I send all the data (with ESC POS commands) directly. The problem with that approach is with the buffer limitation and flow control (handshake). When I send the data too quickly, some data will be discarded when the buffer is full.

After googling for quite a while, I found cups driver for Epson POS TM T88v, tmt-cups- Okay, some progress, I thought. I could choose the driver from cups admin and select the ppd provided. The thing is, when I tried to print some document and image, I kept getting error or the document just hang on the document printing queue. Even if I could get the documents printed, it has different font than the default printer font, and did not look good.
I found some error messages in the /var/log/messages, reporting like the following:
"gs[2599]: segfault at 0 ip 00ad346b sp bf9f4860 error 6 in[74c000+46e000]"
Not sure what exactly the problem is, all I know is it failed. I had high hope for this 'official' driver. Back to square one.

So, then back again sending raw ESC/POS commands directly to the printer using lpr -o raw. The problem is again with the handshake, buffer full. Wow, too much work for printing text. The thing is that the communication is done via usb port. Okay, I tried to communicate to the device using pyUSB, but keep getting permission issue. Yeah, I had to manually change the permissions of the /dev/bus/usb/002/... file. Ouch! Another way is by writing udev rules. Again, too much work to be done. Because even if I solved the permission issue, I still have to read the device status. Not good at all. Too much work.

Fortunately, I found very good information from ubuntuforums. This guys solution is simple, which is by adding 'FileDevice Yes' in /etc/cups/cupsd.conf and add printer with Device URI: file:/dev/usblp0 and set it as Local Raw Printer for make and model. Done!

With that configuration, I could write all the ESC/POS command to a (spool) file and send it to cups using lpr. So, simple! No more issue with handhaking.

Next step is for me is to be able to print out image/logo. I could not do it with the official driver, so I have to find some other way. Back to ESC/POS command.
This guy is really nice. In his blog, he explained in detailed about converting image file to monochomre. This could be done by graphic app, but still interesting to know how to do it programmatically. Then from the monochorome image to bitarray and do some matrix transformation and translate it to byte and send those bits to the printer. Yeah... very-very interesting.
I translate his explanation to python code and, after having a bit confusion with calculating the high_byte and low_byte. I figured how to get those values, and everything works beautifully.

Full appreciation to two guys, I mentioned above, who lead me in good direction, and get what I wanted.


  1. "Fortunately, I found very good information from ubuntuforums. This guys solution is simple, which is by adding 'FileDevice Yes' in /etc/cups/cupsd.conf and add printer with Device URI: file:/dev/usblp0 and set it as Local Raw Printer for make and model. Done!"

    Do you have an example?
    sorry, my english is bad, i cant express me better
    I hope you can help me, now i have this same problem, but, i'm can't solved.
    my mail is bcabezasr [a] gmail
    thank you

  2. Hi owis.
    Which example do you need?
    For /etc/cups/cupsd.conf, just use existing config file and add FileDevice Yes at the end of that conf file.

    For Adding Printer with Device URI, the way I add it on my Ubuntu is by going to System Menu --> Administrations --> Click Add Button, and then enter the Device URI.

    Let me know if you need something else.

  3. The problem with this approach might be it will not print characters in local language as its raw printer. Any idea how to make it work. We use TM-T81 and I initially configured it as file printer in POS. It worked fine with English but when I switched to local language it started displaying ????. So I opted for JavaPOS drivers and ended up using TM BA Drivers (meant for TM-T88V and TM-T220). Once configured in CUPS they work fine but they leave a static left margin blank which results in cropping of receipt from right hand side. Any ideas how to get through this????

    1. Yeah, since I only use english alphabet, the printer works as I expected. Which local language are you using? From what I understand, we could create our own fonts and upload them to the POS, but that's the hard way. If TM BA drivers are working, this is better.
      I don't really understand with 'leave a static left margin blank'. I could only guess that there printing starts a bit further to the middle than you expected, so there could be some truncated text. Is it possible because of incorrect printer head alignment?
      Take a look on printer properties, and under job options, there are some margin text options. Perhaps this could help?
      Do let me know if you figure out how to solve the problem.

  4. Hi,
    I wanted to connect Epson T81 receipt printer with my python program in winodwsXP. i am a beginner, i tried to use pywin32 and detect the printer but none was found and i am not clear how to use the cups driver you mentioned above. i also tried pyserial but as this is a usb printer it appears (ECP Printer Port (LPT1)) not sure how to use it. I dont know there might be lots to explain, but please do help me.
    Thank u so much...

    1. Hi,
      My suggestion to you is to use MS Windows' lpr command. It's a command line program to send a file to printer daemon. The step is to connect the printer to your pc, then configure it as raw printer and use simple name, for the sake of simplicity.
      Now, for the python part, test it by writing esc command + text to a file, and using python's subprocess, execute lpr with the test file name as the argument.
      Let me know if you need more information.

  5. Normally, old receipt printers have problems printing some characters. Some configure the ASCII by integrating the printer with third party software. Anyway, thanks to our current technology, those days are behind us. Today, receipt printers are more functional. However, compatibility is an issue, but this is just normal for business.