Windows 打印到默认热敏打印机
我正在向商店开发程序。该程序需要使用最终打印机打印订单的收据。 我发现打印机遵循ESC/POS标准,发现有一个软件包可以帮助我与打印机平静的python-esc/pos具有接口。但是,要通过USB连接的打印机打印,我需要知道供应商ID和产品ID。我发现了一种使用以下代码在SISTEM上的所有连接打印机找到此方法的方法:
import usb
def is_printer(dev):
if dev.bDeviceClass == 7:
return True
for cfg in dev:
if usb.util.find_descriptor(cfg, bInterfaceClass=7) is not None:
return True
for printer in usb.core.find(find_all=True, custom_match = is_printer):
print('Decimal VendorID=' + str(printer.idVendor) + ' & ProductID=' + str(printer.idProduct) + '\n')
print('Hexadecimal VendorID=' + hex(printer.idVendor) + ' & ProductID=' + hex(printer.idProduct) + '\n\n')
但是,我发现我的客户端已连接到他的系统的多个打印机。我希望能够始终打印到默认打印机。我将感谢您这样做的任何帮助,因为关于默认的最终打印机和所有编辑的文档不多
:我应该澄清一下我没有与我一起使用的热打印机,所以我在这里在黑暗中工作,只是希望它他手中的工作。
I'm developing a program to a shop. The program needs to print the receipt of the order using a termal printer.
I discovered that the printer follows the ESC/POS standard and I found out that there is a package that helps me having an interface with the printer caled python-esc/pos. However, to print throught a USB connected printer, I need to know the Vendor ID and Product ID. I've discovered a way to find this for all the connected printers on the sistem using the following code:
import usb
def is_printer(dev):
if dev.bDeviceClass == 7:
return True
for cfg in dev:
if usb.util.find_descriptor(cfg, bInterfaceClass=7) is not None:
return True
for printer in usb.core.find(find_all=True, custom_match = is_printer):
print('Decimal VendorID=' + str(printer.idVendor) + ' & ProductID=' + str(printer.idProduct) + '\n')
print('Hexadecimal VendorID=' + hex(printer.idVendor) + ' & ProductID=' + hex(printer.idProduct) + '\n\n')
However, I discovered that my client has multiple printers connected to his system. I want to be able to always print to the default printer. I would appreciate any help doing that since there are not many docs about default termal printers and all that
Edit: I should clarify that I do not have a thermal printer with me, so I'm working on the dark here, just hoping that it works in his hands.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论