I am using escposprinter python library for printing my data in thermal printer. It depends on pyusb. the library is working fine in linux . While in windows 7 ,i get the it have some issues. Here are output i get.
File "main.py", line 1, in <module>
from app import app
File "D:\freeth-in-erp-60ab8eb96fad\app\__init__.py", line 94, in <module>
from .api_routes import *
File "D:\freeth-in-erp-60ab8eb96fad\app\api_routes.py", line 44, in <module>
from .printer import pos
File "D:\freeth-in-erp-60ab8eb96fad\app\printer\pos.py", line 14, in <module>
Epson = printer.Usb(idVendor=0x0416,idProduct=0x5011)
File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\escposprinter\print
er.py", line 37, in __init__
self.open()
File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\escposprinter\print
er.py", line 46, in open
if self.device.is_kernel_driver_active(0):
File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\core.py", line
1064, in is_kernel_driver_active
interface)
File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\backend\__init_
_.py", line 365, in is_kernel_driver_active
_not_implemented(self.is_kernel_driver_active)
File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\backend\__init_
_.py", line 81, in _not_implemented
raise NotImplementedError(func.__name__)
NotImplementedError: is_kernel_driver_active
i download the libusb-1.20 from libusb.info and copy file libusb-1.0.dll from MinGW32 and paste in "C:\windows\System32". I get the following result.
from app import app
File "D:\freeth-in-erp-60ab8eb96fad\app\__init__.py", line 94, in <module>
from .api_routes import *
File "D:\freeth-in-erp-60ab8eb96fad\app\api_routes.py", line 44, in <module>
from .printer import pos
File "D:\freeth-in-erp-60ab8eb96fad\app\printer\pos.py", line 14, in <module>
Epson = printer.Usb(idVendor=0x0416,idProduct=0x5011)
File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\escposprinter\print
er.py", line 37, in __init__
self.open()
File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\escposprinter\print
er.py", line 46, in open
if self.device.is_kernel_driver_active(0):
File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\core.py", line
1064, in is_kernel_driver_active
interface)
File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\backend\libusb1
.py", line 898, in is_kernel_driver_active
intf)))
File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\backend\libusb1
.py", line 593, in _check
raise NotImplementedError(_strerror(ret))
NotImplementedError: Operation not supported or unimplemented on this platform
my code is `
from escposprinter import *
from tabulate import tabulate
Epson = printer.Usb(0x0416,0x5011)
from library escposprinter
class Usb(Escpos):
""" Define USB printer """
def __init__(self, idVendor, idProduct, interface=0, in_ep=0x82, out_ep=0x01):
"""
@param idVendor : Vendor ID
@param idProduct : Product ID
@param interface : USB device interface
@param in_ep : Input end point
@param out_ep : Output end point
"""
self.idVendor = idVendor
self.idProduct = idProduct
self.interface = interface
self.in_ep = in_ep
self.out_ep = out_ep
self.open()
def open(self):
""" Search device on USB tree and set is as escpos device """
self.device = usb.core.find(idVendor=self.idVendor, idProduct=self.idProduct)
if self.device is None:
print ("Cable isn't plugged in")
if self.device.is_kernel_driver_active(0):
try:
self.device.detach_kernel_driver(0)
except usb.core.USBError as e:
print ("Could not detatch kernel driver: %s" % str(e))
help me with your suggestion `
The problem is plain and simple that the check whether a kernel driver is active which is not possible on Windows. It seems this library is simply not written for use on Windows.
You can use it on Windows if you delete the last 5 lines from the source code starting with
if self.device.is_kernel_driver_active(0):
or check if the code runs on Windows beforehand and don't call them.Remember on Windows you need to install your own driver. I recommend using Zadig for creating and/or installing the driver.