sending raw data through usb on linux
I'm printing some labels on a Zebra TLP-2844 printer, and have been doing it fine on Windows by sending the EPL instructions to the shared USB printer as follows:
type Label.prn > \my-pc\zebra
and it seems to work with serial ports too, with
type Label.prn > COM1
Now I'm trying to to the same on Linux, but it's getting really hard! My first guess was:
cat Labe开发者_StackOverflow社区l.prn | /dev/bus/usb/005/002
since my printer is on bus 005, device 002 (checked it with lsusb
command) but it doesn't work at all, as I get the following:
bash: /dev/bus/usb/005/002: Permission denied
Any guesses?
The command you did
cat Label.prn | /dev/bus/usb/005/002
will try to run /dev/bus/usb/005/002
, which is not executable, hence "permission denied".
The correct command would be, similar to windows
cat Label.prn > /dev/bus/usb/005/002
However, not sure if you actually can write anything to a printer like that in linux. If the printer is set up properly, you might also try:
lpr Label.prn
In case anyone else is trying to access raw USB printer ports; The "permission denied" problem is circumvented by adding your user to group "lp", like so:
$ sudo usermod -aG lp USERNAME
where USERNAME is your username.
Sorry by My english.
I tested here, my printer TLP2844 connect on USB, in my embedded arm9 board with linux.
I typed in command prompt:
printf "OD\r\nN\r\nD5\r\nS2\r\nZT\r\nQ128, 24\r\nq400\r\nA15,10,0,2,1,1,N,\"TESTE\"\r\nP1\r\nFE\r\n" > /dev/lp0
and... the TEST printed
- You should change access mode for /dev/usb/lp0 device:
sudo chmod a+w /dev/usb/lp0
- And then you can print a label using copy command:
cp test.zpl /dev/usb/lp0
Also you can create your own build system in Sublime Text for example:
{
"cmd": ["cp", "$file", "/dev/usb/lp0"],
"encoding": "utf8"
}
and send files to the printer by pressing Ctrl+B keys immediately after finishing edit the label.
Or you can try my tool to send zpl labels to the printer via TCP/IP: https://github.com/kashamalasha/AutoIt_ZebraTester
It was written on AutoIt Script language, so you need to install AutoIt to build it. Unfortunately there is no description on English, only Russian, but I can write it very soon, if you will need it.
精彩评论