pklaus / brother_ql_web

A Python-based web service to print labels on Brother QL label printers. Based on brother_ql: https://github.com/pklaus/brother_ql
GNU General Public License v3.0
254 stars 124 forks source link

How to detect if device is connected? #37

Closed Abhi0725 closed 3 years ago

Abhi0725 commented 3 years ago

I found that the code will throw "Device not found" error when the device isn't connected. But this error is only at the runtime. Can we detect the device connection without triggering print job?

Abhi0725 commented 3 years ago

Just found that discover in brother_ql.backends.helpers can be used to "discover" Brother devices that are connected. A sample code for anyone who needs it:

from brother_ql.backends.helpers import discover
...
available_devices = discover(backend_identifier='pyusb')
    if len(available_devices):
        print("Printers available!")
    else :
        print("No printer available!")

Closing this issue.