Closed peteruithoven closed 2 years ago
const escpos = require("escpos");
// install escpos-usb adapter module manually
escpos.USB = require("escpos-usb");
// Select the adapter based on your printer type
const device = new escpos.Serial('/dev/usb/lp0');
// encoding is optional
const options = { encoding: "GB18030" /* default */ };
const printer = new escpos.Printer(device, options);
Add a new file in:
/etc/udev/rules.d named usb.rules
It should have the following contents:
SUBSYSTEM=="usb", MODE="0666"
You can do this in terminal quickly: sudo nano /etc/udev/rules.d/usb.rules
Reload rules:
sudo udevadm control --reload
This will make all USB devices readable and writable by all users.
We have 3 printers connected, and we've used udev rules based on serial numbers to create handy symlinks (e.g.
/dev/leg1-printer
). But how do we use these paths to connect to a specific printer, while using the usb protocol?Currently we've found a workaround by using node-usb, opening the device, and reading the serial number. But opening the device to read the serial adds extra permission challenges for example.