簡體   English   中英

在 Python 中使用 Raspberry Pi 將圖像發送到 QL-800 打印機時如何解碼此錯誤?

[英]How to decode this error when using Raspberry Pi to send an image to a QL-800 printer in Python?

一切安裝正常,以獲得兄弟打印機驅動程序的 Raspberry Pi 版本。 我使用了 https://support.brother.com/g/b/downloadtop.aspx?c=us&lang=en&prod=lpql800eus我使用了 https://pypi.org/project/brother-ql/

使用回溯,我如何理解我應該為變量“打印機”使用什么值? 我認為這就是問題所在。

這是代碼:

import pygame
from PIL import Image
from brother_ql.conversion import convert
from brother_ql.backends.helpers import send
from brother_ql.raster import BrotherQLRaster
#####################################################################################################
### Test QR-800 Printer
#####################################################################################################
im = Image.open('QLtest.png')
im.resize((306, 991)) 

backend = 'pyusb'    # 'pyusb', 'linux_kernal', 'network'
model = 'QL-800' # your printer model.

# HERE IS WHERE THE PROBLEM HAPPENS
# The code said to use a value from the Windows usb driver filter of 'usb://0x04f9:0x209b'
# or if have a Raspberry Pi Zero, to use for Linux/Raspberry Pi '/dev/usb/lp0'.
# So I tried with '/dev/usb/lp0' but get error
printer = '/dev/usb/lp0'    

qlr = BrotherQLRaster(model)
qlr.exception_on_warning = True
instructions = convert(
    qlr=qlr, 
    images=[im],    #  Takes a list of file names or PIL objects.
    label='29x90', 
    rotate='90',    # 'Auto', '0', '90', '270'
    threshold=70.0,    # Black and white threshold in percent.
    dither=False, 
    compress=False, 
    red=False,    # Only True if using Red/Black 62 mm label tape.
    dpi_600=False, 
    lq=False,    # True for low quality.
    no_cut=False
)
send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)

這是錯誤:

Traceback (most recent call last):
  File "test_printer.py", line 36, in <module>
    send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)
  File "/home/pi/.local/lib/python3.5/site-packages/brother_ql/backends/helpers.py", line 57, in send
    printer = BrotherQLBackend(printer_identifier)
  File "/home/pi/.local/lib/python3.5/site-packages/brother_ql/backends/pyusb.py", line 79, in __init__
    vendor, product = int(vendor, 16), int(product, 16)
ValueError: invalid literal for int() with base 16: ''

(移動評論回答)

在您的代碼中,您將打印機路徑指定為/dev/usb/lp0但將后端指定為pyusb 對於 USB,庫需要一個類似於“usb://0x04f9:0x209b”的路徑,這會導致您看到的錯誤。 您擁有的路徑 (/dev/usb/lp0) 表示linux_kernel后端。 嘗試相應地更新您的代碼。

backend = 'linux_kernel'

brother_ql庫也可以根據路徑格式猜測后端。

您可以在此處查看模塊源:

https ://github.com/pklaus/brother_ql/blob/142cf744d89a912df729bbf15d35468d780559df/brother_ql/backends/init.py

謝謝大家。 使它起作用的是使用 linux_kernel(而不是 linux_kernal,這是一個錯字)。

這是適用於 QL-800 打印機的示例代碼

import pygame
import time
from PIL import Image
from brother_ql.conversion import convert
from brother_ql.backends.helpers import send
from brother_ql.raster import BrotherQLRaster
#####################################################################################################
### Test QR-800 Printer
#####################################################################################################
QLtest = pygame.image.load('red_black313x156.png')
QLtest = pygame.transform.scale(QLtest,(1044,696)) 
pygame.image.save(QLtest,'RedBlack2_1044x696.png') 

# You will need to convert to PIL object or save to harddrive with pygame.image.save and read back.
# For the Red lable, you need to resize in pygame to AnyWidthx696.  Premium Kiosk uses 1044,696.
image = Image.open('RedBlack2_1044x696.png')

backend = 'linux_kernel'    # 'pyusb', 'linux_kernel', 'network'
model = 'QL-800' # your printer model.

# The author of the code said to use a value from the Windows usb driver filter of 'usb://0x04f9:0x209b'
# or if have a Raspberry Pi Zero, to use for Linux/Raspberry Pi '/dev/usb/lp0'.
printer = '/dev/usb/lp0'    

qlr = BrotherQLRaster(model)
qlr.exception_on_warning = True
'''
To make it work for different types of labels, you need to change the label parameter below.  Here are some examples:
For the 29mm x 90.3mm, use label = '29x90' and red=False and (306, 991) image
For the DK-2251 Black/Red badge, use label='62red' and red=True and (AnyWidth,696) image (note, Premium Kiosk are 1044,696) 
note, if you don't have red or black in your image, you will not see anything for the red/black labels.
To learn more or to use other labels, run these commands in the command line:
     export PATH="${PATH}:~/.local/bin" (just always need to do this first to reach brother_ql)
     brother_ql_create --help (to understand the options in the code below)
     brother_ql_info list-label-sizes (to tell python what label (called Name) and image size (called Printable px)
'''
badge = convert(
    qlr=qlr, 
    images=[image],    #  Takes a list of file names or PIL objects.
    label='62red', 
    rotate='90',    # 'Auto', '0', '90', '270'
    threshold=70.0,    # Black and white threshold in percent.
    dither=False, 
    compress=False, 
    red=True,    # Only True if using Red/Black 62 mm label tape.
    dpi_600=False, 
    lq=False,    # True for low quality.
    no_cut=False
)
send(instructions=badge, printer_identifier=printer, backend_identifier=backend, blocking=True)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM