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-220.127.116.11.tar.gz. 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: segfault at 0 ip 00ad346b sp bf9f4860 error 6 in libgs.so.8.71[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.