Forked from old version of https://git.cyberia.club/starless/catarot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
forest a5887efd7b non-root user 3 months ago
printer first commit 3 months ago
.gitignore first commit 3 months ago
Pipfile first commit 3 months ago
Pipfile.lock first commit 3 months ago
README.md non-root user 3 months ago
terow.jpeg first commit 3 months ago

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!