1

We have 2 lp printers connected to Linux Ubuntu machine. After system boot there are two files created: /dev/usb/lp0 and /dev/usb/lp1. Unfortunately these files are created randomly and we cannot distinguish which one is which. When I echo text in this way:

echo -ne "test" > "/dev/usb/lp0"

everything works fine but of course I don't know which printer will print. We have tried using alias in dev rules (using info gathered from devadm info -q all -a /dev/usb/lp*):

SUBSYSTEM=="usb", KERNELS=="1-1.3.2", SYMLINK+="dr_lewa"

In /dev there is indeed alias created:

lrwxrwxrwx  1 root root          15 Apr 15 14:44 dr_lewa -> bus/usb/001/012

When I try to write to this in the same way as to /dev/usb/lpX error is given:

echo -ne "test" > /dev/dr_lewa
bash: echo: write error: Invalid argument

How can I distinguish two USB serial port lp printers and write to them in normal serial-port-way?

Marcin Zdunek
  • 43
  • 1
  • 4
  • udev has persistent naming rules for storage and network interfaces. You could find or write a similar script for printers. – stark Apr 15 '21 at 16:06
  • You are probably matching too often and attaching the symlink at the wrong level. You need to restrict the match to just when the device name is `/dev/usb/lp0`. Try looking through `sudo udevadm monitor -k -u -p` output when you plug the printer in to see if you can be more specific. – meuh Apr 16 '21 at 14:32

0 Answers0