Forked from old version of https://git.cyberia.club/starless/catarot
Go to file
forest a5887efd7b non-root user 2022-08-18 20:33:10 -05:00
printer first commit 2022-08-18 20:22:22 -05:00
.gitignore first commit 2022-08-18 20:22:22 -05:00
Pipfile first commit 2022-08-18 20:22:22 -05:00
Pipfile.lock first commit 2022-08-18 20:22:22 -05:00
README.md non-root user 2022-08-18 20:33:10 -05:00
terow.jpeg first commit 2022-08-18 20:22:22 -05:00

README.md

python-usb-receipt-printer

small black reciept printer that says terow on the front

(this is not my project, it was cloned from an older version of https://git.cyberia.club/starless/catarot)

To install the dependencies using pipenv

First make sure to install/update pipenv:

sudo pip install pipenv

Then run the install:

pipenv install

To test the project with a USB reciept printer

This works on the TEROW pos-5890k printer.

First lets just try running it:

echo "hello world!!" | pipenv run python3 printer/pprint.py

⚠️ NOTE: this should fail with the error usb.core.USBError: [Errno 13] Access denied (insufficient permissions)

This is expected because we are running our python code as a normal user but by default, we can only access the serial port exposed by the USB device if we become root, for example, with sudo.

🤬 ARGH: both pipenv and sudo modify the shell environment, so using them together is extremely likely to break everything.

Instead of trying to figure out how to get sudo and pipenv to play nice together, I think it might be easier to expose the USB device properly so that our non-root user may access it.

See: https://python-escpos.readthedocs.io/en/latest/user/installation.html#setup-udev-for-usb-printers

Here is a walkthrough of how I did it:

forest@thingpad:~$ lsusb
...
Bus 001 Device 002: ID 0416:5011 Winbond Electronics Corp. Virtual Com Port
...

Great, now we have the device manufacturer id 0416 and the device type id 5011.

Now we just need to come up with a linux group that we want to grant access to the device. For now I will just use the sudo group, the group of users who are allowed to sudo.

You can see the list of groups your user is in with the groups command:

forest@thingpad:~$ groups
forest adm cdrom sudo dip plugdev lpadmin lxd sambashare libvirt

Ok now it's time to create the udev rules file for the printer.

sudo nano /etc/udev/rules.d/99-escpos.rules

Write the following text to the file, including your manufacturer, device type, and group:

SUBSYSTEM=="usb", ATTRS{idVendor}=="0416", ATTRS{idProduct}=="5011", MODE="0664", GROUP="sudo"

We have to restart udev for our changes to take effect:

sudo service udev restart

Also, finally, you will have to power cycle or disconnect and reconnect the printer before the changes will take effect.

Once you have done that, you should be able to run:

echo "hello world!!" | pipenv run python3 printer/pprint.py

And see hello world on your thermal paper!