new CLI: brother_ql
This will slowly deprecate the other CLIs such as * brother_ql_create * brother_ql_print * brother_ql_info * brother_ql_analyze * brother_ql_debug
This commit is contained in:
55
DEBUG.md
55
DEBUG.md
@@ -1,55 +0,0 @@
|
|||||||
|
|
||||||
### DEBUG
|
|
||||||
|
|
||||||
This document shows some ways to help debugging the package brother\_ql.
|
|
||||||
One way is to look into the binary raster instruction file, see the *Analyse* section.
|
|
||||||
The other way is to send those instructions to the printer one by one and check how it reacts, see the *Debug* section.
|
|
||||||
|
|
||||||
#### Analyse
|
|
||||||
|
|
||||||
To analyse a binary file containing Brother QL Raster instructions:
|
|
||||||
|
|
||||||
brother_ql_analyse 720x300_monochrome.bin --loglevel DEBUG
|
|
||||||
|
|
||||||
The tool will dissect your file and print the opcodes to stdout.
|
|
||||||
In addition, it creates PNG images of what the printer's output would look like.
|
|
||||||
They are saved to page0001.png etc. (yes, one .bin file can contain more than one "page").
|
|
||||||
|
|
||||||
This tool also has the `--help` option.
|
|
||||||
|
|
||||||
(This specific tool doesn't work on Python 2.)
|
|
||||||
|
|
||||||
#### Debug
|
|
||||||
|
|
||||||
If your printer has problems printing the instructions file, it may blink its LED (green or red) depending on the model. This can have many reasons, eg.:
|
|
||||||
|
|
||||||
* The selected label doesn't match.
|
|
||||||
* End of paper.
|
|
||||||
* Unsupported opcode (some printers require a mode switching opcode, others fail if such an instruction is sent; some do support data compression, others don't)
|
|
||||||
|
|
||||||
To debug this situation and find out which command could be the culprit, connect your printer via USB. (You don't get any status information via network).
|
|
||||||
You can use the supplied tool `brother_ql_debug` to send your problematic instructions file to the printer. It will be split into single instructions sent one after the other.
|
|
||||||
After every instruction, the printer will be given a chance to send a status response containing error information. Here is an example:
|
|
||||||
|
|
||||||
philipp@lion ~> brother_ql_debug ./720x151_monochrome.bin /dev/usb/lp0
|
|
||||||
INFO: CMD preamble FOUND. Instruction: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [...] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
|
||||||
INFO: CMD init FOUND. Instruction: 1B 40
|
|
||||||
INFO: CMD status request FOUND. Instruction: 1B 69 53
|
|
||||||
INFO: Response from the device: 80 20 42 30 4F 30 00 00 00 00 3E 0A 00 00 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
|
||||||
INFO: Interpretation of the response: 'Reply to status request' (phase: Waiting to receive), 'Continuous length tape' 62x0 mm^2, errors: []
|
|
||||||
INFO: CMD media/quality FOUND. Instruction: 1B 69 7A CE 0A 3E 00 97 00 00 00 01 00
|
|
||||||
INFO: CMD margins FOUND. Instruction: 1B 69 64 23 00
|
|
||||||
INFO: CMD raster FOUND. Instruction: 67 00 5A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 FF FF FF 1F FF FF FF FF FF F0 00 00 00 00 00 0F FF FF 03 FF FF FF FF E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [...] 00 07 FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
|
||||||
INFO: Response from the device: 80 20 42 30 4F 30 00 00 00 00 3E 0A 00 00 15 00 00 00 06 01 00 00 00 00 00 00 00 00 00 00 00 00
|
|
||||||
INFO: Interpretation of the response: 'Phase change' (phase: Printing state), 'Continuous length tape' 62x0 mm^2, errors: []
|
|
||||||
INFO: CMD print FOUND. Instruction: 1A
|
|
||||||
TIME 1.60
|
|
||||||
INFO: Interpretation of the response: 'Printing completed' (phase: Printing state), 'Continuous length tape' 62x0 mm^2, errors: []
|
|
||||||
TIME 1.60
|
|
||||||
INFO: Interpretation of the response: 'Phase change' (phase: Waiting to receive), 'Continuous length tape' 62x0 mm^2, errors: []
|
|
||||||
|
|
||||||
Here, a command file was successfully printed. The last response should state the *Waiting to receive* phase.
|
|
||||||
If you want to confirm the sending of every single command individually, you can add the `--interactive` argument to the command line call.
|
|
||||||
|
|
||||||
If you're seeing any error there, open a new issue on Github containing the debugging output to get your device supported.
|
|
||||||
|
|
||||||
171
LEGACY.md
Normal file
171
LEGACY.md
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
## Legacy User Interfaces
|
||||||
|
|
||||||
|
The following user interfaces of this package are still around but their use is now deprecated and they will
|
||||||
|
be removed in a future release of the package. This documentation still lists the old UI and how it was used.
|
||||||
|
|
||||||
|
### Create
|
||||||
|
|
||||||
|
The command line tool `brother_ql_create` is possibly the most important piece of software in this package.
|
||||||
|
It allows you to create a new instruction file in the label printers' raster language:
|
||||||
|
|
||||||
|
brother_ql_create --model QL-500 ./720x300_monochrome.png > 720x300_monochrome.bin
|
||||||
|
|
||||||
|
If you want to find out about its options, just call the tool with `--help`:
|
||||||
|
|
||||||
|
brother_ql_create --help
|
||||||
|
|
||||||
|
giving:
|
||||||
|
|
||||||
|
usage: brother_ql_create [-h] [--model MODEL] [--label-size LABEL_SIZE]
|
||||||
|
[--rotate {0,90,180,270}] [--threshold THRESHOLD]
|
||||||
|
[--dither] [--compress] [--red] [--600dpi] [--no-cut]
|
||||||
|
[--loglevel LOGLEVEL]
|
||||||
|
image [outfile]
|
||||||
|
|
||||||
|
positional arguments:
|
||||||
|
image The image file to create a label from.
|
||||||
|
outfile The file to write the instructions to. Defaults to
|
||||||
|
stdout.
|
||||||
|
|
||||||
|
optional arguments:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
--model MODEL, -m MODEL
|
||||||
|
The printer model to use. Check available ones with
|
||||||
|
`brother_ql_info list-models`.
|
||||||
|
--label-size LABEL_SIZE, -s LABEL_SIZE
|
||||||
|
The label size (and kind) to use. Check available ones
|
||||||
|
with `brother_ql_info list-label-sizes`.
|
||||||
|
--rotate {0,90,180,270}, -r {0,90,180,270}
|
||||||
|
Rotate the image (counterclock-wise) by this amount of
|
||||||
|
degrees.
|
||||||
|
--threshold THRESHOLD, -t THRESHOLD
|
||||||
|
The threshold value (in percent) to discriminate
|
||||||
|
between black and white pixels.
|
||||||
|
--dither, -d Enable dithering when converting the image to b/w. If
|
||||||
|
set, --threshold is meaningless.
|
||||||
|
--compress, -c Enable compression (if available with the model).
|
||||||
|
Takes more time but results in smaller file size.
|
||||||
|
--red Create a label to be printed on black/red/white tape
|
||||||
|
(only with QL-8xx series on DK-22251 labels). You must
|
||||||
|
use this option when printing on black/red tape, even
|
||||||
|
when not printing red.
|
||||||
|
--600dpi Print with 600x300 dpi available on some models.
|
||||||
|
Provide your image as 600x600 dpi; perpendicular to
|
||||||
|
the feeding the image will be resized to 300dpi.
|
||||||
|
--no-cut Don't cut the tape after printing the label.
|
||||||
|
--loglevel LOGLEVEL Set to DEBUG for verbose debugging output to stderr.
|
||||||
|
|
||||||
|
The image argument should be a PNG/GIF/JPEG image file.
|
||||||
|
Here is the output of `brother_ql_info list-label-sizes` listing the available options for `--label-size`:
|
||||||
|
|
||||||
|
Supported label sizes:
|
||||||
|
Name Printable px Description
|
||||||
|
12 106 (12 mm endless)
|
||||||
|
29 306 (29 mm endless)
|
||||||
|
38 413 (38 mm endless)
|
||||||
|
50 554 (50 mm endless)
|
||||||
|
54 590 (54 mm endless)
|
||||||
|
62 696 (62 mm endless)
|
||||||
|
102 1164 (102 mm endless)
|
||||||
|
17x54 165 x 566 (17 x 54 mm^2)
|
||||||
|
17x87 165 x 956 (17 x 87 mm^2)
|
||||||
|
23x23 202 x 202 (23 x 23 mm^2)
|
||||||
|
29x42 306 x 425 (29 x 42 mm^2)
|
||||||
|
29x90 306 x 991 (29 x 90 mm^2)
|
||||||
|
39x90 413 x 991 (38 x 90 mm^2)
|
||||||
|
39x48 425 x 495 (39 x 48 mm^2)
|
||||||
|
52x29 578 x 271 (52 x 29 mm^2)
|
||||||
|
62x29 696 x 271 (62 x 29 mm^2)
|
||||||
|
62x100 696 x 1109 (62 x 100 mm^2)
|
||||||
|
102x51 1164 x 526 (102 x 51 mm^2)
|
||||||
|
102x152 1164 x 1660 (102 x 152 mm^2)
|
||||||
|
d12 94 x 94 (12 mm diameter, round)
|
||||||
|
d24 236 x 236 (24 mm diameter, round)
|
||||||
|
d58 618 x 618 (58 mm diameter, round)
|
||||||
|
|
||||||
|
**Pro Tip™**:
|
||||||
|
For the best results, use image files with the matching pixel dimensions. Die-cut labels have to be in the exact pixel dimensions stated above. For endless label rolls, you can provide image files with a pixel width as stated above. If you provide a file with different dimensions when creating an endless label file, it will be scaled to fit the width.
|
||||||
|
|
||||||
|
### Print
|
||||||
|
|
||||||
|
Once you have a Brother QL instruction file, you can send it to the printer like this:
|
||||||
|
|
||||||
|
cat my_label.bin > /dev/usb/lp1
|
||||||
|
|
||||||
|
Be sure to have permission to write to the device (usually adding yourself to the *lp* group is sufficient.
|
||||||
|
|
||||||
|
Or via network (if you have a LAN/WLAN enabled Brother QL):
|
||||||
|
|
||||||
|
nc 192.168.0.23 9100 < my_label.bin
|
||||||
|
|
||||||
|
You can also use the tool `brother_ql_print` (Py3 only) to send the instructions to your printer:
|
||||||
|
|
||||||
|
brother_ql_print 720x151_monochrome.bin /dev/usb/lp0
|
||||||
|
# or
|
||||||
|
brother_ql_print --backend network 720x151_monochrome.bin tcp://192.168.0.23:9100
|
||||||
|
# or (requires PyUSB: `pip install pyusb`)
|
||||||
|
brother_ql_print 720x151_monochrome.bin usb://0x04f9:0x2015
|
||||||
|
# or if you have multiple ones connected:
|
||||||
|
brother_ql_print 720x151_monochrome.bin usb://0x04f9:0x2015/000M6Z401370
|
||||||
|
# where 000M6Z401370 is the serial number (see lsusb output).
|
||||||
|
|
||||||
|
If your printer has problems printing the instructions file, it may blink its LED (green or red) depending on the model. This can have many reasons, eg.:
|
||||||
|
|
||||||
|
* The selected label doesn't match (make sure `--red` has been passed to `brother_ql_create` if you're using black/red labels).
|
||||||
|
* End of paper.
|
||||||
|
* Unsupported opcode (wrong `--model` when using `brother_ql_create`?)
|
||||||
|
|
||||||
|
### DEBUG
|
||||||
|
|
||||||
|
In case of trouble printing an instruction file, there are some ways to help debugging.
|
||||||
|
One way is to look into the binary raster instruction file, see the *Analyse* section.
|
||||||
|
The other way is to send those instructions to the printer one by one and check how it reacts, see the *Debug* section.
|
||||||
|
|
||||||
|
#### Analyse
|
||||||
|
|
||||||
|
To analyse a binary file containing Brother QL Raster instructions:
|
||||||
|
|
||||||
|
brother_ql_analyse 720x300_monochrome.bin --loglevel DEBUG
|
||||||
|
|
||||||
|
The tool will dissect your file and print the opcodes to stdout.
|
||||||
|
In addition, it creates PNG images of what the printer's output would look like.
|
||||||
|
They are saved to page0001.png etc. (yes, one .bin file can contain more than one "page").
|
||||||
|
|
||||||
|
This tool also has the `--help` option.
|
||||||
|
|
||||||
|
(This specific tool doesn't work on Python 2.)
|
||||||
|
|
||||||
|
#### Debug
|
||||||
|
|
||||||
|
If your printer has problems printing the instructions file, it may blink its LED (green or red) depending on the model. This can have many reasons, eg.:
|
||||||
|
|
||||||
|
* The selected label doesn't match.
|
||||||
|
* End of paper.
|
||||||
|
* Unsupported opcode (some printers require a mode switching opcode, others fail if such an instruction is sent; some do support data compression, others don't)
|
||||||
|
|
||||||
|
To debug this situation and find out which command could be the culprit, connect your printer via USB. (You don't get any status information via network).
|
||||||
|
You can use the supplied tool `brother_ql_debug` to send your problematic instructions file to the printer. It will be split into single instructions sent one after the other.
|
||||||
|
After every instruction, the printer will be given a chance to send a status response containing error information. Here is an example:
|
||||||
|
|
||||||
|
philipp@lion ~> brother_ql_debug ./720x151_monochrome.bin /dev/usb/lp0
|
||||||
|
INFO: CMD preamble FOUND. Instruction: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [...] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||||
|
INFO: CMD init FOUND. Instruction: 1B 40
|
||||||
|
INFO: CMD status request FOUND. Instruction: 1B 69 53
|
||||||
|
INFO: Response from the device: 80 20 42 30 4F 30 00 00 00 00 3E 0A 00 00 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||||
|
INFO: Interpretation of the response: 'Reply to status request' (phase: Waiting to receive), 'Continuous length tape' 62x0 mm^2, errors: []
|
||||||
|
INFO: CMD media/quality FOUND. Instruction: 1B 69 7A CE 0A 3E 00 97 00 00 00 01 00
|
||||||
|
INFO: CMD margins FOUND. Instruction: 1B 69 64 23 00
|
||||||
|
INFO: CMD raster FOUND. Instruction: 67 00 5A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 FF FF FF 1F FF FF FF FF FF F0 00 00 00 00 00 0F FF FF 03 FF FF FF FF E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [...] 00 07 FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||||
|
INFO: Response from the device: 80 20 42 30 4F 30 00 00 00 00 3E 0A 00 00 15 00 00 00 06 01 00 00 00 00 00 00 00 00 00 00 00 00
|
||||||
|
INFO: Interpretation of the response: 'Phase change' (phase: Printing state), 'Continuous length tape' 62x0 mm^2, errors: []
|
||||||
|
INFO: CMD print FOUND. Instruction: 1A
|
||||||
|
TIME 1.60
|
||||||
|
INFO: Interpretation of the response: 'Printing completed' (phase: Printing state), 'Continuous length tape' 62x0 mm^2, errors: []
|
||||||
|
TIME 1.60
|
||||||
|
INFO: Interpretation of the response: 'Phase change' (phase: Waiting to receive), 'Continuous length tape' 62x0 mm^2, errors: []
|
||||||
|
|
||||||
|
Here, a command file was successfully printed. The last response should state the *Waiting to receive* phase.
|
||||||
|
If you want to confirm the sending of every single command individually, you can add the `--interactive` argument to the command line call.
|
||||||
|
|
||||||
|
If you're seeing any error there, open a new issue on Github containing the debugging output to get your device supported.
|
||||||
|
|
||||||
174
README.md
174
README.md
@@ -51,125 +51,81 @@ This package was mainly created for use with Python 3. The essential functionali
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
The main user interface of this package are its command line tools.
|
The main user interface of this package is the command line tool `brother_ql`.
|
||||||
You can also use its functionality from your own Python code (yet, there is no dedicated API documentation).
|
|
||||||
The following sections show how to use the most important CLI tools.
|
|
||||||
|
|
||||||
### Create
|
Usage: brother_ql [OPTIONS] COMMAND [ARGS]...
|
||||||
|
|
||||||
The command line tool `brother_ql_create` is possibly the most important piece of software in this package.
|
|
||||||
It allows you to create a new instruction file in the label printers' raster language:
|
|
||||||
|
|
||||||
brother_ql_create --model QL-500 ./720x300_monochrome.png > 720x300_monochrome.bin
|
|
||||||
|
|
||||||
If you want to find out about its options, just call the tool with `--help`:
|
|
||||||
|
|
||||||
brother_ql_create --help
|
|
||||||
|
|
||||||
giving:
|
|
||||||
|
|
||||||
usage: brother_ql_create [-h] [--model MODEL] [--label-size LABEL_SIZE]
|
|
||||||
[--rotate {0,90,180,270}] [--threshold THRESHOLD]
|
|
||||||
[--dither] [--compress] [--red] [--600dpi] [--no-cut]
|
|
||||||
[--loglevel LOGLEVEL]
|
|
||||||
image [outfile]
|
|
||||||
|
|
||||||
positional arguments:
|
Command line interface for the brother_ql Python package.
|
||||||
image The image file to create a label from.
|
|
||||||
outfile The file to write the instructions to. Defaults to
|
|
||||||
stdout.
|
|
||||||
|
|
||||||
optional arguments:
|
Options:
|
||||||
-h, --help show this help message and exit
|
-b, --backend [pyusb|network|linux_kernel]
|
||||||
--model MODEL, -m MODEL
|
-m, --model [QL-500|QL-550|QL-560|QL-570|QL-580N|QL-650TD|QL-700|QL-710W|QL-720NW|QL-800|QL-810W|QL-820NWB|QL-1050|QL-1060N]
|
||||||
The printer model to use. Check available ones with
|
-p, --printer PRINTER_IDENTIFIER
|
||||||
`brother_ql_info list-models`.
|
The identifier for the printer. This could
|
||||||
--label-size LABEL_SIZE, -s LABEL_SIZE
|
be a string like tcp://192.168.1.21:9100 for
|
||||||
The label size (and kind) to use. Check available ones
|
a networked printer or
|
||||||
with `brother_ql_info list-label-sizes`.
|
usb://0x04f9:0x2015/000M6Z401370 for a
|
||||||
--rotate {0,90,180,270}, -r {0,90,180,270}
|
printer connected via USB.
|
||||||
Rotate the image (counterclock-wise) by this amount of
|
--debug
|
||||||
degrees.
|
--help Show this message and exit.
|
||||||
--threshold THRESHOLD, -t THRESHOLD
|
|
||||||
The threshold value (in percent) to discriminate
|
Commands:
|
||||||
between black and white pixels.
|
analyze interpret a binary file containing raster...
|
||||||
--dither, -d Enable dithering when converting the image to b/w. If
|
discover find connected label printers
|
||||||
set, --threshold is meaningless.
|
info list available choices (for labels or models)
|
||||||
--compress, -c Enable compression (if available with the model).
|
print Print a label
|
||||||
Takes more time but results in smaller file size.
|
send send an instruction file to the printer
|
||||||
--red Create a label to be printed on black/red/white tape
|
|
||||||
(only with QL-8xx series on DK-22251 labels). You must
|
|
||||||
use this option when printing on black/red tape, even
|
|
||||||
when not printing red.
|
|
||||||
--600dpi Print with 600x300 dpi available on some models.
|
|
||||||
Provide your image as 600x600 dpi; perpendicular to
|
|
||||||
the feeding the image will be resized to 300dpi.
|
|
||||||
--no-cut Don't cut the tape after printing the label.
|
|
||||||
--loglevel LOGLEVEL Set to DEBUG for verbose debugging output to stderr.
|
|
||||||
|
|
||||||
The image argument should be a PNG/GIF/JPEG image file.
|
There are some global options available such as --model and --printer.
|
||||||
Here is the output of `brother_ql_info list-label-sizes` listing the available options for `--label-size`:
|
They can also be provided by environment variables (`BROTHER_QL_MODEL` and `BROTHER_QL_PRINTER`).
|
||||||
|
|
||||||
Supported label sizes:
|
The global options are followed by a command such as `info` or `print`.
|
||||||
Name Printable px Description
|
The most important command is the `print` command and here is its CLI signature:
|
||||||
12 106 (12 mm endless)
|
|
||||||
29 306 (29 mm endless)
|
|
||||||
38 413 (38 mm endless)
|
|
||||||
50 554 (50 mm endless)
|
|
||||||
54 590 (54 mm endless)
|
|
||||||
62 696 (62 mm endless)
|
|
||||||
102 1164 (102 mm endless)
|
|
||||||
17x54 165 x 566 (17 x 54 mm^2)
|
|
||||||
17x87 165 x 956 (17 x 87 mm^2)
|
|
||||||
23x23 202 x 202 (23 x 23 mm^2)
|
|
||||||
29x42 306 x 425 (29 x 42 mm^2)
|
|
||||||
29x90 306 x 991 (29 x 90 mm^2)
|
|
||||||
39x90 413 x 991 (38 x 90 mm^2)
|
|
||||||
39x48 425 x 495 (39 x 48 mm^2)
|
|
||||||
52x29 578 x 271 (52 x 29 mm^2)
|
|
||||||
62x29 696 x 271 (62 x 29 mm^2)
|
|
||||||
62x100 696 x 1109 (62 x 100 mm^2)
|
|
||||||
102x51 1164 x 526 (102 x 51 mm^2)
|
|
||||||
102x152 1164 x 1660 (102 x 152 mm^2)
|
|
||||||
d12 94 x 94 (12 mm diameter, round)
|
|
||||||
d24 236 x 236 (24 mm diameter, round)
|
|
||||||
d58 618 x 618 (58 mm diameter, round)
|
|
||||||
|
|
||||||
**Pro Tip™**:
|
Usage: brother_ql print [OPTIONS] IMAGE [IMAGE] ...
|
||||||
For the best results, use image files with the matching pixel dimensions. Die-cut labels have to be in the exact pixel dimensions stated above. For endless label rolls, you can provide image files with a pixel width as stated above. If you provide a file with different dimensions when creating an endless label file, it will be scaled to fit the width.
|
|
||||||
|
Print a label of the provided IMAGE.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-l, --label [12|29|38|50|54|62|102|17x54|17x87|23x23|29x42|29x90|39x90|39x48|52x29|62x29|62x100|102x51|102x152|d12|d24|d58]
|
||||||
|
The label (size, type - die-cut or endless).
|
||||||
|
Run `brother_ql info list-labels` for a full
|
||||||
|
list including ideal pixel dimensions.
|
||||||
|
-r, --rotate [auto|0|90|180|270]
|
||||||
|
Rotate the image (counterclock-wise) by this
|
||||||
|
amount of degrees.
|
||||||
|
-t, --threshold FLOAT The threshold value (in percent) to
|
||||||
|
discriminate between black and white pixels.
|
||||||
|
-d, --dither Enable dithering when converting the image
|
||||||
|
to b/w. If set, --threshold is meaningless.
|
||||||
|
-c, --compress Enable compression (if available with the
|
||||||
|
model). Label creation can take slightly
|
||||||
|
longer but the resulting instruction size is
|
||||||
|
normally considerably smaller.
|
||||||
|
--red Create a label to be printed on
|
||||||
|
black/red/white tape (only with QL-8xx
|
||||||
|
series on DK-22251 labels). You must use
|
||||||
|
this option when printing on black/red tape,
|
||||||
|
even when not printing red.
|
||||||
|
--600dpi Print with 600x300 dpi available on some
|
||||||
|
models. Provide your image as 600x600 dpi;
|
||||||
|
perpendicular to the feeding the image will
|
||||||
|
be resized to 300dpi.
|
||||||
|
--lq Print with low quality (faster). Default is
|
||||||
|
high quality.
|
||||||
|
--no-cut / --cut Don't cut the tape after printing the label.
|
||||||
|
--help Show this message and exit.
|
||||||
|
|
||||||
### Print
|
So, printing an image file onto 62mm endless tape on a QL-710W label printer can be as easy as:
|
||||||
|
|
||||||
Once you have a Brother QL instruction file, you can send it to the printer like this:
|
export BROTHER_QL_PRINTER=tcp://192.168.1.21
|
||||||
|
export BROTHER_QL_MODEL=QL-710W
|
||||||
|
brother_ql print -l 62 my_image.png
|
||||||
|
|
||||||
cat my_label.bin > /dev/usb/lp1
|
### Legacy command line tools
|
||||||
|
|
||||||
Be sure to have permission to write to the device (usually adding yourself to the *lp* group is sufficient.
|
For a long time, this project provided multiple command line tools, such as `brother_ql_create`, `brother_ql_print`, `brother_ql_analyze`, and more.
|
||||||
|
A documentation of their usage can be found in the [LEGACY](https://github.com/pklaus/brother_ql/blob/master/LEGACY.md).
|
||||||
Or via network (if you have a LAN/WLAN enabled Brother QL):
|
|
||||||
|
|
||||||
nc 192.168.0.23 9100 < my_label.bin
|
|
||||||
|
|
||||||
You can also use the tool `brother_ql_print` (Py3 only) to send the instructions to your printer:
|
|
||||||
|
|
||||||
brother_ql_print 720x151_monochrome.bin /dev/usb/lp0
|
|
||||||
# or
|
|
||||||
brother_ql_print --backend network 720x151_monochrome.bin tcp://192.168.0.23:9100
|
|
||||||
# or (requires PyUSB: `pip install pyusb`)
|
|
||||||
brother_ql_print 720x151_monochrome.bin usb://0x04f9:0x2015
|
|
||||||
# or if you have multiple ones connected:
|
|
||||||
brother_ql_print 720x151_monochrome.bin usb://0x04f9:0x2015/000M6Z401370
|
|
||||||
# where 000M6Z401370 is the serial number (see lsusb output).
|
|
||||||
|
|
||||||
If your printer has problems printing the instructions file, it may blink its LED (green or red) depending on the model. This can have many reasons, eg.:
|
|
||||||
|
|
||||||
* The selected label doesn't match (make sure `--red` has been passed to `brother_ql_create` if you're using black/red labels).
|
|
||||||
* End of paper.
|
|
||||||
* Unsupported opcode (wrong `--model` when using `brother_ql_create`?)
|
|
||||||
|
|
||||||
## Debugging
|
|
||||||
|
|
||||||
More info on how to debug difficult situations is to be found in the [DEBUG doc](https://github.com/pklaus/brother_ql/blob/master/DEBUG.md).
|
|
||||||
|
|
||||||
## Links
|
## Links
|
||||||
|
|
||||||
|
|||||||
120
brother_ql/cli.py
Executable file
120
brother_ql/cli.py
Executable file
@@ -0,0 +1,120 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# Python standard library
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# external dependencies
|
||||||
|
import click
|
||||||
|
|
||||||
|
# imports from this very package
|
||||||
|
from brother_ql.devicedependent import models, label_sizes, label_type_specs, DIE_CUT_LABEL, ENDLESS_LABEL, ROUND_DIE_CUT_LABEL
|
||||||
|
from brother_ql.backends import available_backends, backend_factory
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger('brother_ql')
|
||||||
|
|
||||||
|
|
||||||
|
printer_help = "The identifier for the printer. This could be a string like tcp://192.168.1.21:9100 for a networked printer or usb://0x04f9:0x2015/000M6Z401370 for a printer connected via USB."
|
||||||
|
@click.group()
|
||||||
|
@click.option('-b', '--backend', type=click.Choice(available_backends), envvar='BROTHER_QL_BACKEND')
|
||||||
|
@click.option('-m', '--model', type=click.Choice(models), envvar='BROTHER_QL_MODEL')
|
||||||
|
@click.option('-p', '--printer', metavar='PRINTER_IDENTIFIER', envvar='BROTHER_QL_PRINTER', help=printer_help)
|
||||||
|
@click.option('--debug', is_flag=True)
|
||||||
|
@click.pass_context
|
||||||
|
def cli(ctx, *args, **kwargs):
|
||||||
|
""" Command line interface for the brother_ql Python package. """
|
||||||
|
|
||||||
|
backend = kwargs.get('backend', None)
|
||||||
|
model = kwargs.get('model', None)
|
||||||
|
printer = kwargs.get('printer', None)
|
||||||
|
debug = kwargs.get('debug')
|
||||||
|
|
||||||
|
# Store the general CLI options in the context meta dictionary.
|
||||||
|
# The name corresponds to the second half of the respective envvar:
|
||||||
|
ctx.meta['MODEL'] = model
|
||||||
|
ctx.meta['BACKEND'] = backend
|
||||||
|
ctx.meta['PRINTER'] = printer
|
||||||
|
|
||||||
|
logging.basicConfig(level='DEBUG' if debug else 'INFO')
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.pass_context
|
||||||
|
def discover(ctx):
|
||||||
|
""" find connected label printers """
|
||||||
|
backend = ctx.meta.get('BACKEND', 'pyusb')
|
||||||
|
discover_and_list_available_devices(backend)
|
||||||
|
|
||||||
|
def discover_and_list_available_devices(backend):
|
||||||
|
from brother_ql.backends.helpers import discover
|
||||||
|
available_devices = discover(backend_identifier=backend)
|
||||||
|
from brother_ql.output_helpers import log_discovered_devices, textual_description_discovered_devices
|
||||||
|
log_discovered_devices(available_devices)
|
||||||
|
print(textual_description_discovered_devices(available_devices))
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.argument('info', click.Choice(('labels', 'models')))
|
||||||
|
@click.pass_context
|
||||||
|
def info(ctx, *args, **kwargs):
|
||||||
|
""" list available choices (for labels or models) """
|
||||||
|
if kwargs['info'] == 'models':
|
||||||
|
"""List the models (choices for --model)
|
||||||
|
|
||||||
|
List the models that can be used with this software.
|
||||||
|
Those are the choices avaiable for the --model option.
|
||||||
|
"""
|
||||||
|
print('Supported models:')
|
||||||
|
for model in models: print(" " + model)
|
||||||
|
|
||||||
|
elif kwargs['info'] == 'labels':
|
||||||
|
"""
|
||||||
|
List labels (types and sizes).
|
||||||
|
|
||||||
|
This command lists all labels (label types and label sizes)
|
||||||
|
that can be used with this software. """
|
||||||
|
from brother_ql.output_helpers import textual_label_description
|
||||||
|
print(textual_label_description(label_sizes))
|
||||||
|
|
||||||
|
@cli.command('print', short_help='Print a label')
|
||||||
|
@click.argument('images', nargs=-1, metavar='IMAGE [IMAGE] ...')
|
||||||
|
@click.option('-l', '--label', type=click.Choice(label_sizes), envvar='BROTHER_QL_LABEL', help='The label (size, type - die-cut or endless). Run `brother_ql info list-labels` for a full list including ideal pixel dimensions.')
|
||||||
|
@click.option('-r', '--rotate', type=click.Choice(('auto', '0', '90', '180', '270')), default='auto', help='Rotate the image (counterclock-wise) by this amount of degrees.')
|
||||||
|
@click.option('-t', '--threshold', type=float, default=70.0, help='The threshold value (in percent) to discriminate between black and white pixels.')
|
||||||
|
@click.option('-d', '--dither', is_flag=True, help='Enable dithering when converting the image to b/w. If set, --threshold is meaningless.')
|
||||||
|
@click.option('-c', '--compress', is_flag=True, help='Enable compression (if available with the model). Label creation can take slightly longer but the resulting instruction size is normally considerably smaller.')
|
||||||
|
@click.option('--red', is_flag=True, help='Create a label to be printed on black/red/white tape (only with QL-8xx series on DK-22251 labels). You must use this option when printing on black/red tape, even when not printing red.')
|
||||||
|
@click.option('--600dpi', 'dpi_600', is_flag=True, help='Print with 600x300 dpi available on some models. Provide your image as 600x600 dpi; perpendicular to the feeding the image will be resized to 300dpi.')
|
||||||
|
@click.option('--lq', is_flag=True, help='Print with low quality (faster). Default is high quality.')
|
||||||
|
@click.option('--no-cut/--cut', is_flag=True, help="Don't cut the tape after printing the label.")
|
||||||
|
@click.pass_context
|
||||||
|
def print_cmd(ctx, *args, **kwargs):
|
||||||
|
""" Print a label of the provided IMAGE. """
|
||||||
|
backend = ctx.meta.get('BACKEND', 'pyusb')
|
||||||
|
model = ctx.meta.get('MODEL')
|
||||||
|
printer = ctx.meta.get('PRINTER')
|
||||||
|
from brother_ql.conversion import convert
|
||||||
|
from brother_ql.backends.helpers import send
|
||||||
|
from brother_ql.raster import BrotherQLRaster
|
||||||
|
qlr = BrotherQLRaster(model)
|
||||||
|
qlr.exception_on_warning = True
|
||||||
|
instructions = convert(qlr=qlr, **kwargs)
|
||||||
|
send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)
|
||||||
|
|
||||||
|
@cli.command(name='analyze', help='interpret a binary file containing raster instructions for the Brother QL-Series printers')
|
||||||
|
@click.argument('instructions', type=click.File('rb'))
|
||||||
|
@click.option('-f', '--filename-format', help="Filename format string. Default is: label{counter:04d}.png.")
|
||||||
|
@click.pass_context
|
||||||
|
def analyze_cmd(ctx, *args, **kwargs):
|
||||||
|
from brother_ql.reader import BrotherQLReader
|
||||||
|
br = BrotherQLReader(kwargs.get('instructions'))
|
||||||
|
if kwargs.get('filename_format'): br.filename_fmt = kwargs.get('filename_format')
|
||||||
|
br.analyse()
|
||||||
|
|
||||||
|
@cli.command(name='send', short_help='send an instruction file to the printer')
|
||||||
|
@click.argument('instructions', type=click.File('rb'))
|
||||||
|
@click.pass_context
|
||||||
|
def send_cmd(ctx, *args, **kwargs):
|
||||||
|
from brother_ql.backends.helpers import send
|
||||||
|
send(instructions=kwargs['instructions'].read(), printer_identifier=ctx.meta.get('PRINTER'), backend_identifier=ctx.meta.get('BACKEND'), blocking=True)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
cli()
|
||||||
2
setup.py
2
setup.py
@@ -26,6 +26,7 @@ setup(name='brother_ql',
|
|||||||
'brother_ql.backends'],
|
'brother_ql.backends'],
|
||||||
entry_points = {
|
entry_points = {
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
'brother_ql = brother_ql.cli:cli',
|
||||||
'brother_ql_analyse = brother_ql.brother_ql_analyse:main',
|
'brother_ql_analyse = brother_ql.brother_ql_analyse:main',
|
||||||
'brother_ql_create = brother_ql.brother_ql_create:main',
|
'brother_ql_create = brother_ql.brother_ql_create:main',
|
||||||
'brother_ql_print = brother_ql.brother_ql_print:main',
|
'brother_ql_print = brother_ql.brother_ql_print:main',
|
||||||
@@ -37,6 +38,7 @@ setup(name='brother_ql',
|
|||||||
zip_safe = True,
|
zip_safe = True,
|
||||||
platforms = 'any',
|
platforms = 'any',
|
||||||
install_requires = [
|
install_requires = [
|
||||||
|
"click",
|
||||||
"future",
|
"future",
|
||||||
"packbits",
|
"packbits",
|
||||||
"pillow>=3.3.0",
|
"pillow>=3.3.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user