Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printer Problem on Unix-like systems USBNotFoundError: USB device not found #125

Closed
ernestoluciano opened this issue Jun 6, 2020 · 55 comments
Labels

Comments

@ernestoluciano
Copy link

Traceback (most recent call last):
File "/Users/Ernesto/FQM/app/printer.py", line 131, in listp
for ll in usb.core.find(find_all=True, custom_match=find_class(7)):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/usb/core.py", line 1263, in find
raise NoBackendError('No backend available')
usb.core.NoBackendError: No backend available

@ernestoluciano
Copy link
Author

I solved. this with $brew install libusb

@ernestoluciano
Copy link
Author

The problem when i click a ticket is:

Traceback (most recent call last):
File "/Users/Ernesto/FQM/app/views/core.py", line 129, in serial
printer = assign(int(ticket_settings.vendor, 16), int(ticket_settings.product, 16),
File "/Users/Ernesto/FQM/app/printer.py", line 123, in assign
printer = getp.Usb(v, p, 0, in_ep, out_ep)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/escpos/printer.py", line 51, in init
self.open()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/escpos/printer.py", line 57, in open
raise USBNotFoundError("Device not found or cable not plugged in.")
escpos.exceptions.USBNotFoundError: USB device not found

@mrf345
Copy link
Owner

mrf345 commented Jun 6, 2020

Do you mind attaching a screenshot of Customization > Ticket > Select USB Printer options and your data.sqlite file here ?

Interesting 🤔 libusb should be installed by default alongside PyUSB package, but probably that's a MacOS issue. Did you encounter the same error on Linux ?

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 6, 2020 via email

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 6, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 6, 2020

PyUSB is already in deploy.txt . if you mean libusb then that's not possible. it's a usb driver written in C that should be installed by default on your system, or gets installed by the PyUSB package.

But if the issue is still reproducible on Linux it means, there's still an issue on FQM side with parsing your printer ID. Can you please attach a screen shot of Customization > Ticket > Select USB Printer options and/or your data.sqlite file here ?

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 6, 2020 via email

@ernestoluciano
Copy link
Author

why?: GET serial, should be USB

127.0.0.1 - - [2020-06-05 21:23:50] "GET /serial/1/1 HTTP/1.1" 302 828 0.074705

Traceback (most recent call last):
File "/Users/Ernesto/FQM/app/views/core.py", line 129, in serial
printer = assign(int(ticket_settings.vendor, 16), int(ticket_settings.product, 16),
File "/Users/Ernesto/FQM/app/printer.py", line 123, in assign
printer = getp.Usb(v, p, 0, in_ep, out_ep)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/escpos/printer.py", line 51, in init
self.open()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/escpos/printer.py", line 57, in open
raise USBNotFoundError("Device not found or cable not plugged in.")
escpos.exceptions.USBNotFoundError: USB device not found

127.0.0.1 - - [2020-06-05 21:23:50] "GET /serial/1/1 HTTP/1.1" 302 828 0.074705

@mrf345
Copy link
Owner

mrf345 commented Jun 6, 2020

Sorry, there is no problem with slush under linux, only Mac have the problem

No worries, good to hear printing is working correctly on Linux.

This is my data.sqlite:

alembic_version offices settings users
aliases operators slides vids
displays printers slides_c
media roles tasks
mtasks serials touchs

Sorry i wasn't clear enough, i meant attaching the data.sqlite file itself. Instead could please run and attach SELECT * FROM printers;

why?: GET serial, should be USB

Because printed is selected in Customization > Tickets > Select type of ticket to use : so FQM is trying to generate a ticket using the selected printer, but it can't find it.

@ernestoluciano
Copy link
Author

I'm running python with the command python3, is that a problem? because with python i get the next error when installing:

ERROR: Command errored out with exit status 1:
command: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/_k/92dzwhm531j5whxhswt06ymc0000gn/T/pip-install-Bn28IR/Flask-Googletrans/setup.py'"'"'; file='"'"'/private/var/folders/_k/92dzwhm531j5whxhswt06ymc0000gn/T/pip-install-Bn28IR/Flask-Googletrans/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/_k/92dzwhm531j5whxhswt06ymc0000gn/T/pip-pip-egg-info-FzdvFM
cwd: /private/var/folders/_k/92dzwhm531j5whxhswt06ymc0000gn/T/pip-install-Bn28IR/Flask-Googletrans/
Complete output (5 lines):
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/_k/92dzwhm531j5whxhswt06ymc0000gn/T/pip-install-Bn28IR/Flask-Googletrans/setup.py", line 5, in
encoding='utf-8') as f:
TypeError: 'encoding' is an invalid keyword argument for this function
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

so i decided to run FQM like this: python3 run.py --cli --port 8080 --ip 192.168.5.27

Here the link to the data https://wetransfer.com/downloads/a411fb5fcd07291063702e3b79702a0420200606015045/e83af78cee8dfb084e871ab86a8708d520200606015105/d49843

@mrf345
Copy link
Owner

mrf345 commented Jun 6, 2020

/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/

Yes. FQM officially supports Python 3.7 only. But your log is showing 2.7 which's no longer supported.

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 6, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 6, 2020

To run in python3.7 I need to put python3 run, the log I sent you is when I run python without the 3

Sorry i thought you were asking, why it's not supporting the default python on MacOS.

Thanks for attaching the data.db file. The printer details seems to be parsed and stored correctly.
Yet the PyUSB package fails to find the printer. There's not much that can be done from FQM side at this point. Other than adding a warning that printing on MacOS is not supported 🤷‍♂️

Thanks for taking the time, really appreciate it!

@mrf345 mrf345 added the bug label Jun 6, 2020
@mrf345 mrf345 changed the title Printer Problem Printer Problem on Unix-like systems USBNotFoundError: USB device not found Jun 6, 2020
@mrf345
Copy link
Owner

mrf345 commented Jun 6, 2020

Hi @ernestoluciano , i took another look at your data.db::printers and discovered another issue with parsing the printer ID. I'm about to merge a PR #127 that resolves it.

Please let me know if the issue still persists.

@mrf345 mrf345 closed this as completed in 4b4b5b6 Jun 6, 2020
mrf345 added a commit that referenced this issue Jun 6, 2020
Fix printer ID parsing on unix-like. Resolves #125
@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 7, 2020 via email

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 7, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 7, 2020

f4efa0d99d19, Adding strict_pulling flag setting.

Looks like it got stuck on running the first migration file there. The easiest solution is to remove data.sqlite like you did. But i think it's an issue that needs to be fixed. I've moved it to #129

I deleted the data.sqlite and now is working. System works like charm, no more crash, BUT, still not printing. I can lp foo.txt from my system, but I don’t know why the python-escpos can’t, have you tried using CUPS instate escpos?

That's good to hear. I think python-escpos is the most stable library in Python for POS printing as far as I've tested. But definitely doesn't support every printer out there. Did it generate any errors this time ? BTW what's the brand and name of the printer you're testing with ?

@mrf345 mrf345 reopened this Jun 7, 2020
@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 7, 2020 via email

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 7, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 7, 2020

The problem is esc/pos need the next command
lsusb -vvv -d 0519:0003 | grep iInterface lsusb -vvv -d 0519:0003 | grep bEndpointAddress | grep OUT

Good point. I think I've encountered a similar issue once before while trying to get an old EPSON printer to work. I think the issue as you've pointed out: failing to get the USB bEndpointAddress::OUT.

  • So this is what's currently happening as far as i can tell:

FQM tries to get the in_ep and out_ep of the USB devices. using printer = PyUSB::usb.core.find()[0] and then it fails and gets a silenced exception when trying to access the device parsed configuration with printer.get_active_configuration() this part of the code-base can be found here.

Therefore it will default to not assigning any values to en_in and en_out so the default values set by python-escpos will be used when escpos.printers.Usb(vendor_id, product_id) here and that will result in the last exception you've attached:

image

Really not sure if there's anything that could be done on pyton-escpos side to fix this 🤔

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 7, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 7, 2020

That's the spirit! I think we can take the easy route here. Add a flag setting to enable or disable using lp* on Unix-like systems instead of python-escpos and PyUSB. what do you think ?

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 7, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 7, 2020

Alright that confirms it. I will be working on lp alternative implementation. on the main time could you please open an issue on python-escpos repository, they might be able to resolve it before then.

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 7, 2020 via email

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 7, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 7, 2020

Hopefully late tomorrow, if everything went well. If not, it will have to wait until the weekend.

@mrf345
Copy link
Owner

mrf345 commented Jun 8, 2020

Hi @ernestoluciano , i'm about to merge a PR #131 (comment) that adds support for printing with lp.
Please let me know if the issue still persists.

@mrf345 mrf345 closed this as completed in bba0489 Jun 8, 2020
mrf345 added a commit that referenced this issue Jun 8, 2020
Add `lp` printing option for unix-like. Resolves #125
@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 8, 2020

Not sure why ? i didn't update any package in the last change. I added a new setting to enable printing with lp command instead of python-escpos.

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 8, 2020

Are sure the setting is enabled ?
lp_flag_setting

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 8, 2020

Maybe the commands aren't fully compatible. Can you try to run the following commands from the terminal and attach the output here:

lpstat -a

and replace printer_name with your printer name:

echo "testing ticket" > testing.text
lp -d printer_name -o raw `pwd`/testing.text

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 8, 2020

It didn't find the file, make sure the file exists echo "testing" > testing.txt and then:

lp -d Star_TS143_STR_T_001_ -o raw `pwd`/testing.txt

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 8, 2020

The -o raw argument allows us to to send binaries to the printer, as far as i know. Well let's try to send binaries without it. can you paste the following inside foo.txt and send it without -o raw:

\x1d!3\x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x01\x1dB\x00FQM\n\x1b!\x00\x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x01\x1dB\x00Version 0.7 beta\x1b!\x00\x1b{\x00\x1db\x00\x1bE\x00\x1b-\x01\x1bM\x00\x1ba\x01\x1dB\x00\nhttps://fqms.github.io\n\x1b!\x00\x1b! \x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x01\x1dB\x00\n---------------\n\x1d!"\x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x01\x1dB\x00\ntesting\n\x1b!\x00\x1b! \x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x01\x1dB\x00\n---------------\n\x1b!\x00\x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x00\x1dB\x00\nOffice : testing\n\nCurrent ticket : testing\n\nTickets ahead : testing\n\nTask : testing\nTime : 2020-06-08 19:57:34\n\n\n\n\n\n\n\x1dV\x00\x1d!3\x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x01\x1dB\x00FQM\n\x1b!\x00\x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x01\x1dB\x00Version 0.7 beta\x1b!\x00\x1b{\x00\x1db\x00\x1bE\x00\x1b-\x01\x1bM\x00\x1ba\x01\x1dB\x00\nhttps://fqms.github.io\n\x1b!\x00\x1b! \x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x01\x1dB\x00\n---------------\n\x1d!"\x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x01\x1dB\x00\ntesting\n\x1b!\x00\x1b! \x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x01\x1dB\x00\n---------------\n\x1b!\x00\x1b{\x00\x1db\x00\x1bE\x00\x1b-\x00\x1bM\x00\x1ba\x00\x1dB\x00\nOffice : testing\n\nCurrent ticket : testing\n\nTickets ahead : testing\n\nTask : testing\nTime : 2020-06-08 19:57:37\n\n\n\n\n\n\n\x1dV\x00

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 8, 2020

so using it without the -o raw isn't an option since it will not read the binary instructions.
Let's checkout the list of options for your printer, please run and attach: lpoptions -p Star_TSP143__STR_T_001_ -l

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 8, 2020

Based on the options showing in the last command output and a little bit of googling, it seems to me the issue's with the Star printer not supporting raw instructions unless it's sent through a local network connection here 🤔

If that's the case, unfortunately i don't think there's a way of getting it to work via the USB port with FQM. And adding support for local network printers is another hell i don't intend to explore anytime soon 🤣

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 8, 2020

It didn't work. you've tested already, the printer didn't convert the binary instructions #125 (comment)

@ernestoluciano
Copy link
Author

ernestoluciano commented Jun 8, 2020 via email

@mrf345
Copy link
Owner

mrf345 commented Jun 8, 2020

Thanks, good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants