In this post, I’ll step through how to get a thermal receipt printer with USB interface appearing on Linux. The aim of this is to be able to point a driver such as escpos-php at the device. The printer used here is an Epson TM-T20, which is very common in point-of-sale environments.
I have previously written quite a bit about how to use thermal receipt printer protocols, but the previous printer I covered had only a network interface, not USB like this one:
The directions below are for Debian, but could be adapted for any other Linux.
Find the device file
Plug in your printer, and check that usblp
sees it:
|
|
This kernel module makes your printer visible as a device file, so that it can be accessed in the old-fashioned way. Find the new device file under /dev/usb
:
|
|
In my case, this was /dev/usb/lp1
. The next step is to see if you can write to it:
|
|
Chances are, you will get a permission denied error at this point, so find out what group the printer is in:
|
|
Which will show output something like:
|
|
This file is owned by group lp
(“line printer”). If your username was bob
, you would add yourself to this group using:
|
|
If you plan to build a web-based point-of-sale system with this, then also add the www-data
user to that group.
Now log out and back in, and the previous test should now be working:
|
|
Troubleshooting: Check usblp
If these steps don’t work, then your computer either doesn’t have, or isn’t using usblp
You’ll need to check a few things:
- Install a different linux-image if the driver is not on your computer at all.
modprobe
orinsmod usblp
- blacklist a vendor driver which has claimed the interface.
- run
lsusb -v
andusb-devices
(look fordriver=
)
Printing something useful
As a duplicated section from my earlier post, the printer uses ESC/POS, which means it accepts plaintext with some special commands for formatting.
A simple receipt-generator, foo.php
, might look like this:
|
|
And you would send it to the printer like this:
|
|
Scaling this up
The codes are quite tricky to work with manually, which is why I put together the escpos-php driver. You can find it at:
The previous example would be written using escpos-php as:
|
|
This would be sent to the printer by loading it from the web, or running the script on the command-line:
|
|