pklaus / brother_ql

Python package for the raster language protocol of the Brother QL series label printers (QL-500, QL-550, QL-560, QL-570, QL-700, QL-710W, QL-720NW, QL-800, QL-810W, QL-820NWB, QL-1050, QL-1060N and more).
GNU General Public License v3.0
558 stars 165 forks source link

[Brother QL-570] Black Square Printout #8

Closed nmaas87 closed 7 years ago

nmaas87 commented 7 years ago

Hello pklaus and thanks a lot for the awesome idea! I am using QL-570 with Raspberry Pis as Invoice Printer, however, the cups drivers are less than usable and so I stumbled upon your tool - and really want to use it (as my input data is transfered as png files via python.. so.. could be good 👍)

However, the setup sadly does not work. I am using an QL-570 with 54 / 590 / (54 mm endless) tape and the -to-be-wished- result would be an all page print out of the reciepe as seen in the added file. However, I only get an black square with the first file (cafe.png) and an black square with less "white space" / tape (cafe90.png). I included the bin files and png files as well.

And following errors:

root@demo:/home/pi/test# brother_ql_create --model QL-570 --label-size 54 ./cafe.png cafe.bin
root@demo:/home/pi/test# brother_ql_create --model QL-570 --label-size 54 ./cafe90.png cafe90.bin
root@demo:/home/pi/test# brother_ql_print cafe.bin /dev/usb/lp0
Traceback (most recent call last):
  File "/usr/local/bin/brother_ql_print", line 9, in <module>
    load_entry_point('brother-ql==0.6-dev', 'console_scripts', 'brother_ql_print')()
  File "/usr/local/lib/python2.7/dist-packages/brother_ql/brother_ql_print.py", line 85, in main
    result = interpret_response(data)
  File "/usr/local/lib/python2.7/dist-packages/brother_ql/reader.py", line 157, in interpret_response
    if error_info_1 & (1 << error_bit):
TypeError: unsupported operand type(s) for &: 'str' and 'int'
root@demo:/home/pi/test# brother_ql_print cafe90.bin /dev/usb/lp0
Traceback (most recent call last):
  File "/usr/local/bin/brother_ql_print", line 9, in <module>
    load_entry_point('brother-ql==0.6-dev', 'console_scripts', 'brother_ql_print')()
  File "/usr/local/lib/python2.7/dist-packages/brother_ql/brother_ql_print.py", line 85, in main
    result = interpret_response(data)
  File "/usr/local/lib/python2.7/dist-packages/brother_ql/reader.py", line 157, in interpret_response
    if error_info_1 & (1 << error_bit):
TypeError: unsupported operand type(s) for &: 'str' and 'int'

You can download the file here https://jctixx.de/download/QL570Test.zip

If I can help you out with test prints or such, just let me know. Also, I tried to play with the treshold setting - it did not make it less or more black :(

pklaus commented 7 years ago

Thanks for the bug report. This issue should be fixed in 743d963. Please upgrade and test again.

nmaas87 commented 7 years ago

Absolutely awesome! It works like a treat! 👍 Thanks a lot for the very quick help! Do you have any intention to make that program into a kind of Python API, so that you could call it as a function with an file and the needed variables to include that in own software? (It ain't needed, as one can really fastly call it via shell commands and such, but just as a question :)!)

pklaus commented 7 years ago

By the way: The errors in _brother_qlprint show that you are using it with Python 2. It was not made for this. I spent some work to make _brother_qlcreate work with Python 2, however (which is why it worked at all). You can simply print by using cat cafe.bin > /dev/usb/lp0 instead of brother_ql_print.

pklaus commented 7 years ago

Do you have any intention to make that program into a kind of Python API, so that you could call it as a function with an file and the needed variables to include that in own software?

You can do:

from brother_ql import BrotherQLRaster, create_label
qlr = BrotherQLRaster("QL-570")
# image can be a PIL/Pillow Image() object or a file name to the GIF/PNG/JPEG image:
create_label(qlr, image, "62", threshold=70, cut=True)
# The binary image output is then available in this variable:
qlr.data

You can send this to your printer via simple Python:

import os
dev = os.open('/dev/usb/lp0', os.O_RDWR)
try:
    data = os.write(dev, qlr.data)
except KeyboardInterrupt:
    pass
finally:
    os.close(dev)

Or on Python 3 you can use brother_ql's more high-level variants:

from brother_ql.backends.linux_kernel import BrotherQLBackendLinuxKernel as BrotherQLBackend
printer = BrotherQLBackend("/dev/usb/lp0")
printer.write(qlr.data)

Unfortunately the API is not yet documented. It was also changing a lot until now. The above should, however, be quite stable.