使用escpos连接SureMark 4610打印机时无限卡顿的问题排查
Key Observations from Your Setup
- Your printer is detected as a Human Interface Device (HID) (interface class 0x3) with interrupt IN endpoint
0x82 - The code hangs when initializing the
printer.Usbinstance frompython-escpos - Windows 10 with official printer drivers installed
Actionable Fixes
1. Add Missing Output Endpoint Configuration
The printer.Usb class requires both input and output endpoints for communication. Your device descriptor doesn't explicitly list an OUT endpoint, so try common HID output endpoint values (0x01 or 0x02):
from escpos import printer # Try out_ep=0x01 first, then 0x02 if it fails p = printer.Usb(idVendor=0x04B3, idProduct=0x4535, timeout=10, in_ep=0x82, out_ep=0x01) print(p.idProduct)
Use a tool like USBView to find the exact OUT endpoint if these values don't work.
2. Resolve Windows HID Driver Conflict
Windows may lock the device using its default HID driver, blocking python-escpos access:
- Open Device Manager
- Locate the printer under Human Interface Devices
- Right-click > Update Driver > Browse my computer for drivers > Let me pick from a list
- Select USB Printing Support (install the official IBM driver first if this option is missing)
3. Run Script with Elevated Privileges
Windows requires admin rights to access USB devices directly:
- Right-click your command prompt/Python IDE
- Select Run as administrator
- Execute your script again
4. Update python-escpos
Older versions may have HID compatibility issues:
pip install --upgrade python-escpos
5. Isolate Issue with Raw USB Test
Use pyusb directly to check if device access works outside python-escpos:
import usb.core import usb.util dev = usb.core.find(idVendor=0x04B3, idProduct=0x4535) if not dev: raise ValueError("Device not found") # Detach conflicting kernel drivers for cfg in dev: for intf in cfg: if dev.is_kernel_driver_active(intf.bInterfaceNumber): try: dev.detach_kernel_driver(intf.bInterfaceNumber) except usb.core.USBError as e: print(f"Failed to detach driver: {e}") dev.set_configuration() # Send a printer initialization command try: dev.write(0x01, b'\x1B\x40') print("Command sent successfully") except usb.core.USBError as e: print(f"Communication error: {e}")
If this works, the issue lies with python-escpos's device handling; if not, focus on driver/permission fixes.
内容的提问来源于stack exchange,提问作者P3X-774

