Improvement of printer definitions

This commit is contained in:
Ircama 2024-07-08 00:14:54 +02:00
parent bd4581b951
commit f7d9e305d8
3 changed files with 185 additions and 39 deletions

View file

@ -133,22 +133,25 @@ Here is a simple procedure to download that DB and run *parse_devices.py* to sea
```bash ```bash
curl -o devices.xml https://codeberg.org/attachments/147f41a3-a6ea-45f6-8c2a-25bac4495a1d curl -o devices.xml https://codeberg.org/attachments/147f41a3-a6ea-45f6-8c2a-25bac4495a1d
python3 parse_devices.py -m XP-205 python3 parse_devices.py -i -m XP-205
``` ```
After generating the related printer configuration, *epson_print_conf.py* shall be manually edited to copy/paste the output of *parse_devices.py* within its PRINTER_CONFIG dictionary. After generating the related printer configuration, *epson_print_conf.py* shall be manually edited to copy/paste the output of *parse_devices.py* within its PRINTER_CONFIG dictionary.
The `-m` option is mandatory and is used to filter the printer model in scope. If the produced output is not referred to the target model, use part of the model name as a filter (e.g., only the digits, like `parse_devices.py -m 315`) and select the appropriate model from the output. The `-m` option is mandatory and is used to filter the printer model in scope. If the produced output is not referred to the target model, use part of the model name as a filter (e.g., only the digits, like `parse_devices.py -i -m 315`) and select the appropriate model from the output.
Program usage: Program usage:
``` ```
python3 parse_devices.py [-h] -m PRINTER_MODEL [-d] [-t] [-v] [-f] [-e] [-c CONFIG_FILE] python3 parse_devices.py [-h] -m PRINTER_MODEL [-l LINE_LENGTH] [-i] [-d] [-t] [-v] [-f] [-e] [-c CONFIG_FILE]
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
-m PRINTER_MODEL, --model PRINTER_MODEL -m PRINTER_MODEL, --model PRINTER_MODEL
Printer model. Example: -m XP-205 Printer model. Example: -m XP-205
-l LINE_LENGTH, --line LINE_LENGTH
Set line length of the output (default: 120)
-i, --indent Indent output of 4 spaces
-d, --debug Print debug information -d, --debug Print debug information
-t, --traverse Traverse the XML, dumping content related to the printer model -t, --traverse Traverse the XML, dumping content related to the printer model
-v, --verbose Print verbose information -v, --verbose Print verbose information
@ -156,11 +159,9 @@ optional arguments:
-e, --errors Add last_printer_fatal_errors -e, --errors Add last_printer_fatal_errors
-c CONFIG_FILE, --config CONFIG_FILE -c CONFIG_FILE, --config CONFIG_FILE
use the XML configuration file to generate the configuration use the XML configuration file to generate the configuration
Generate printer configuration from devices.xml
``` ```
The output is better viewed when also installing [black](https://pypi.org/project/black/). The output is better formatted when also installing [black](https://pypi.org/project/black/).
### Other utilities ### Other utilities

View file

@ -60,27 +60,56 @@ class EpsonPrinter:
"Light cyan": {"1S": 0x6E, "2S": 0x6F, "3S": 0x9B}, "Light cyan": {"1S": 0x6E, "2S": 0x6F, "3S": 0x9B},
}, },
"serial_number": range(0xE7, 0xF0), "serial_number": range(0xE7, 0xF0),
# untested
}, },
"WF-7525": { "WF-7525": {
"read_key": [101, 0], "read_key": [101, 0],
"write_key": b'Sasanqua', "write_key": b'Sasanqua',
"alias": ["WF-7515"], "alias": ["WF-7515"],
"main_waste": {"oids": [20, 21], "divider": 196.5}, "main_waste": {"oids": [20, 21, 59], "divider": 196.5},
"borderless_waste": {"oids": [22, 23], "divider": 52.05}, "borderless_waste": {"oids": [22, 23, 59], "divider": 52.05},
"serial_number": range(192, 202), "serial_number": range(192, 202),
"stats": { "stats": {
"Maintenance required level of 1st waste ink counter": [60], "Maintenance required level of 1st waste ink counter": [60],
"Maintenance required level of 2nd waste ink counter": [61], "Maintenance required level of 2nd waste ink counter": [61],
"Manual cleaning counter": [131],
"Timer cleaning counter": [134],
"Ink replacement cleaning counter": [133],
"Total print pass counter": [159, 158, 157, 156],
"Total print page counter": [147, 146, 145, 144],
"Total scan counter": [471, 470, 469, 468],
"Total scan counter % (ADF)": [475, 474, 473, 472],
}, },
"raw_waste_reset": { "ink_replacement_counters": {
"Black": {"1L": 242, "1S": 243, "2S": 244},
"Yellow": {"1S": 248, "2S": 249, "3S": 250},
"Magenta": {"1S": 251, "2S": 252, "3S": 253},
"Cyan": {"1S": 245, "2S": 246, "3S": 247},
},
"raw_waste_reset": {
20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0, 59: 0, 60: 94, 61: 94 20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0, 59: 0, 60: 94, 61: 94
} }
# uncompleted
}, },
"L355": { "L355": {
"read_key": [65, 9], "read_key": [65, 9],
# uncompleted "write_key": b"Wakatobi",
"main_waste": {"oids": [24, 25, 30], "divider": 65.0},
"raw_waste_reset": {24: 0, 25: 0, 30: 0, 28: 0, 29: 0, 46: 94},
"stats": {
"Manual cleaning counter": [147],
"Timer cleaning counter": [149],
"Total print pass counter": [171, 170, 169, 168],
"Total print page counter - Color": [439, 438, 437, 436],
"Total print page counter - Black": [435, 434, 433, 432],
"Total print page counter - Blank": [443, 442, 441, 440],
"Total print page counter": [167, 166, 165, 164],
"Total scan counter": [471, 470, 469, 468],
"First TI received time": [173, 172],
"Ink replacement counter - Black": [242],
"Ink replacement counter - Yellow": [244],
"Ink replacement counter - Magenta": [245],
"Ink replacement counter - Cyan": [243],
},
"serial_number": range(192, 202),
}, },
"L366": { "L366": {
"read_key": [130, 2], "read_key": [130, 2],
@ -90,44 +119,93 @@ class EpsonPrinter:
"stats": { "stats": {
"Maintenance required level of 1st waste ink counter": [46], "Maintenance required level of 1st waste ink counter": [46],
"Maintenance required level of 2nd waste ink counter": [47], "Maintenance required level of 2nd waste ink counter": [47],
"Ink replacement counter - Black": [242],
"Ink replacement counter - Yellow": [243],
"Ink replacement counter - Cyan": [244],
"Ink replacement counter - Magenta": [245],
}, },
"raw_waste_reset": { "raw_waste_reset": {
24: 0, 25: 0, 30: 0, 26: 0, 27: 0, 34: 0, 28: 0, 29: 0 24: 0, 25: 0, 30: 0, 26: 0, 27: 0, 34: 0, 28: 0, 29: 0,
} 49: 0, 46: 94, 47: 94
# uncompleted },
"serial_number": range(192, 202),
}, },
"L3250": { "L3250": {
"read_key": [74, 54], "read_key": [74, 54],
"write_key": b'Maribaya', "write_key": b'Maribaya',
"serial_number": range(1604, 1614), "serial_number": range(1604, 1614),
"main_waste": {"oids": [48, 49], "divider": 63.45}, "main_waste": {"oids": [48, 49, 47], "divider": 63.45},
"second_waste": {"oids": [50, 51], "divider": 34.15}, "second_waste": {"oids": [50, 51, 47], "divider": 34.15},
"third_waste": {"oids": [252, 253], "divider": 13}, "third_waste": {"oids": [252, 253, 254], "divider": 13},
"raw_waste_reset": { "raw_waste_reset": {
48: 0, 49: 0, 50: 0, 51: 0, 252: 0, 253: 0 48: 0, 49: 0, 47: 0, 52: 0, 53: 0, 54: 94, 50: 0, 51: 0,
55: 94, 28: 0, 252: 0, 253: 0, 254: 0, 255: 94,
}, },
"last_printer_fatal_errors": [ "last_printer_fatal_errors": [
289, 288, 291, 290, 293, 292, 295, 294, 297, 296, 1831, 1832, 289, 288, 291, 290, 293, 292, 295, 294, 297, 296, 1831, 1832,
1833, 1834, 1835, 2037, 2036, 2039, 2038, 2041, 2040, 2043, 1833, 1834, 1835, 2037, 2036, 2039, 2038, 2041, 2040, 2043,
2042, 2045, 2044], 2042, 2045, 2044],
# uncompleted "stats": {
"Manual cleaning counter": [90],
"Timer cleaning counter": [89],
"Power cleaning counter": [91],
"Total print pass counter": [133, 132, 131, 130],
"Total print page counter": [776, 775, 774, 773],
"Total scan counter": [1843, 1842, 1841, 1840],
},
},
"ET-2400": {
"alias": ["ET-2401", "ET-2403", "ET-2405"],
"read_key": [74, 54],
"write_key": b"Maribaya",
"main_waste": {"oids": [48, 49, 47], "divider": 63.46},
"borderless_waste": {"oids": [50, 51, 47], "divider": 34.16},
"third_waste": {"oids": [252, 253, 254], "divider": 13.0},
"raw_waste_reset": {
48: 0, 49: 0, 47: 0, 52: 0, 53: 0, 54: 94, 50: 0, 51: 0,
55: 94, 28: 0, 252: 0, 253: 0, 254: 0, 255: 94,
},
"stats": {
"Maintenance required level of 1st waste ink counter": [54],
"Maintenance required level of 2nd waste ink counter": [55],
"Maintenance required level of 3rd waste ink counter": [255],
"Manual cleaning counter": [90],
"Timer cleaning counter": [89],
"Power cleaning counter": [91],
"Total print pass counter": [133, 132, 131, 130],
"Total print page counter": [776, 775, 774, 773],
"Total scan counter": [1843, 1842, 1841, 1840],
},
"serial_number": range(1604, 1614),
}, },
"ET-2600": { "ET-2600": {
"alias": ["ET-2650"], "alias": ["ET-2650", "L395"],
"read_key": [16, 8], "read_key": [16, 8],
"write_key": b'Sinabung', "write_key": b'Sinabung',
"main_waste": {"oids": [24, 25], "divider": 62.06}, "main_waste": {"oids": [24, 25, 30], "divider": 62.06},
"raw_waste_reset": {24: 0, 25: 0, 30: 0, 28: 0, 29: 0, 46: 94},
"stats": {
"Manual cleaning counter": [147],
"Timer cleaning counter": [149],
"Power cleaning counter": [148],
"Total print pass counter": [171, 170, 169, 168],
"Total print page counter": [167, 166, 165, 164],
"Total scan counter": [471, 470, 469, 468],
"First TI received time": [173, 172],
},
"serial_number": range(192, 202),
}, },
"ET-2720": { "ET-2720": {
"alias": ["ET-2714", "ET-2721", "ET-2723", "ET-2725"], "alias": ["ET-2714", "ET-2721", "ET-2723", "ET-2725"],
"read_key": [151, 7], "read_key": [151, 7],
"write_key": b'Maribaya', "write_key": b'Maribaya',
"main_waste": {"oids": [48, 49], "divider": 63.45}, "main_waste": {"oids": [48, 49, 47], "divider": 63.45},
"second_waste": {"oids": [50, 51], "divider": 34.15}, "borderless_waste": {"oids": [50, 51, 47], "divider": 34.15},
"same-as": "ET-2700" "same-as": "ET-2700"
# tested
}, },
"ET-2750": { "ET-2750": {
"serial_number": range(1604, 1614),
"alias": ["ET-2751", "ET-2756"], "alias": ["ET-2751", "ET-2756"],
"read_key": [73, 8], "read_key": [73, 8],
"write_key": b"Arantifo", "write_key": b"Arantifo",
@ -156,37 +234,73 @@ class EpsonPrinter:
"L3160": { "L3160": {
"read_key": [151, 7], "read_key": [151, 7],
"write_key": b'Maribaya', "write_key": b'Maribaya',
"main_waste": {"oids": [48, 49, 47], "divider": 63.46},
"borderless_waste": {"oids": [50, 51, 47], "divider": 34.16},
"stats": {
"Maintenance required level of 1st waste ink counter": [54],
"Maintenance required level of 2nd waste ink counter": [55],
"First TI received time": [9, 8],
"Total print pass counter": [133, 132, 131, 130],
"Total print page counter": [776, 775, 774, 773],
"Total scan counter": [1843, 1842, 1841, 1840],
"Ink replacement counter - Black": [554],
"Ink replacement counter - Cyan": [555],
"Ink replacement counter - Magenta": [556],
"Ink replacement counter - Yellow": [557],
},
"same-as": "L4160" "same-as": "L4160"
# uncompleted
}, },
"L405": { "L405": {
"read_key": [0x95, 0x03], "read_key": [149, 3],
"write_key": b'Maninjau', "write_key": b"Maninjau",
"raw_waste_reset": { "main_waste": {"oids": [24, 25, 30], "divider": 62.07},
0x18:0, 0x19:0, 0x1c:0, 0x1d:0, 0x2e:0x5e, 0x1e:0 "raw_waste_reset": {24: 0, 25: 0, 30: 0, 28: 0, 29: 0, 46: 94},
"stats": {
"Manual cleaning counter": [147],
"Timer cleaning counter": [149],
"Power cleaning counter": [148],
"Total print pass counter": [171, 170, 169, 168],
"Total print page counter": [167, 166, 165, 164],
"Total scan counter": [471, 470, 469, 468],
"First TI received time": [173, 172],
"Ink replacement counter - Black": [242],
"Ink replacement counter - Yellow": [244],
"Ink replacement counter - Magenta": [245],
"Ink replacement counter - Cyan": [243],
}, },
"serial_number": range(192, 202),
}, },
"L4160": { "L4160": {
"read_key": [73, 8], "read_key": [73, 8],
"write_key": b'Arantifo', "write_key": b'Arantifo',
"main_waste": {"oids": [48, 49, 47], "divider": 109.13},
"borderless_waste": {"oids": [50, 51, 47], "divider": 16.31},
"stats": { "stats": {
"Maintenance required level of 1st waste ink counter": [54], "Maintenance required level of 1st waste ink counter": [54],
"Maintenance required level of 2nd waste ink counter": [55], "Maintenance required level of 2nd waste ink counter": [55],
"First TI received time": [9, 8],
"Total print pass counter": [133, 132, 131, 130],
"Total print page counter - rear feed": [755, 754, 753, 752],
"Total scan counter": [1843, 1842, 1841, 1840],
"Ink replacement counter - Black": [554],
"Ink replacement counter - Cyan": [555],
"Ink replacement counter - Magenta": [556],
"Ink replacement counter - Yellow": [557],
}, },
"serial_number": range(1604, 1614),
"raw_waste_reset": { "raw_waste_reset": {
48: 0, 49: 0, 47: 0, 52: 0, 53: 0, 48: 0, 49: 0, 47: 0, 52: 0, 53: 0,
54: 94, 50: 0, 51: 0, 55: 94, 28: 0 54: 94, 50: 0, 51: 0, 55: 94, 28: 0
} }
# uncompleted
}, },
"XP-315": { "XP-315": {
"alias": ["XP-312", "XP-313"], "alias": ["XP-312", "XP-313"],
"read_key": [129, 8], "read_key": [129, 8],
"write_key": b'Wakatobi',
"printer_head_id_h": range(122, 126), "printer_head_id_h": range(122, 126),
"printer_head_id_f": [129], "printer_head_id_f": [129],
"main_waste": {"oids": [24, 25, 30], "divider": 69}, "main_waste": {"oids": [24, 25, 30], "divider": 69},
"borderless_waste": {"oids": [26, 27, 34], "divider": 32.53}, "borderless_waste": {"oids": [26, 27, 34], "divider": 32.53},
"write_key": b'Wakatobi',
"serial_number": range(192, 202), "serial_number": range(192, 202),
"stats": { "stats": {
"Manual cleaning counter": [147], "Manual cleaning counter": [147],
@ -215,7 +329,6 @@ class EpsonPrinter:
"Cyan": {"1B": 245, "1S": 243, "1L": 244}, "Cyan": {"1B": 245, "1S": 243, "1L": 244},
}, },
"last_printer_fatal_errors": [60, 203, 204, 205, 206, 0x01d3], "last_printer_fatal_errors": [60, 203, 204, 205, 206, 0x01d3],
# untested
}, },
"XP-422": { "XP-422": {
"read_key": [85, 5], "read_key": [85, 5],
@ -319,6 +432,7 @@ class EpsonPrinter:
# uncompleted # uncompleted
}, },
"XP-3150": { "XP-3150": {
"alias": ["XP-3151", "XP-3155"],
"read_key": [80, 9], "read_key": [80, 9],
"write_key": b'Bidadari', "write_key": b'Bidadari',
"serial_number": range(1604, 1614), "serial_number": range(1604, 1614),
@ -386,6 +500,14 @@ class EpsonPrinter:
"stats": { "stats": {
"Maintenance required level of 1st waste ink counter": [54], "Maintenance required level of 1st waste ink counter": [54],
"Maintenance required level of 2nd waste ink counter": [55], "Maintenance required level of 2nd waste ink counter": [55],
"First TI received time": [9, 8],
"Total print pass counter": [133, 132, 131, 130],
"Total print page counter": [776, 775, 774, 773],
"Total scan counter": [1843, 1842, 1841, 1840],
"Ink replacement counter - Black": [554],
"Ink replacement counter - Cyan": [555],
"Ink replacement counter - Magenta": [556],
"Ink replacement counter - Yellow": [557],
}, },
"raw_waste_reset": { "raw_waste_reset": {
48: 0, 49: 0, 47: 0, # Data of 1st counter 48: 0, 49: 0, 47: 0, # Data of 1st counter

View file

@ -3,6 +3,7 @@ import logging
import re import re
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import itertools import itertools
import textwrap
def to_ranges(iterable): def to_ranges(iterable):
iterable = sorted(set(iterable)) iterable = sorted(set(iterable))
@ -61,7 +62,9 @@ def generate_config(config, traverse, add_fatal_errors, full, printer_model):
"Tag: %s, Attributes: %s, Specs: %s", "Tag: %s, Attributes: %s, Specs: %s",
printer.tag, printer.attrib, printer.attrib['specs'] printer.tag, printer.attrib, printer.attrib['specs']
) )
printer_name = printer.attrib["short"] printer_short_name = printer.attrib["short"]
printer_long_name = printer.attrib["title"]
printer_model_name = printer.attrib["model"]
chars = {} chars = {}
for spec in specs: for spec in specs:
logging.debug("SPEC: %s", spec) logging.debug("SPEC: %s", spec)
@ -207,7 +210,10 @@ def generate_config(config, traverse, add_fatal_errors, full, printer_model):
chars["sendlen"] = int(s.text, 16) chars["sendlen"] = int(s.text, 16)
if full and s.tag == "readlen": if full and s.tag == "readlen":
chars["readlen"] = int(s.text, 16) chars["readlen"] = int(s.text, 16)
printer_config[printer_name] = chars if full:
chars["long_name"] = printer_long_name
chars["model"] = printer_model_name
printer_config[printer_short_name] = chars
return printer_config return printer_config
@ -226,6 +232,21 @@ if __name__ == "__main__":
help='Printer model. Example: -m XP-205', help='Printer model. Example: -m XP-205',
required=True) required=True)
parser.add_argument(
'-l',
'--line',
dest='line_length',
type=int,
help='Set line length of the output (default: 120)',
default=120)
parser.add_argument(
'-i',
'--indent',
dest='indent',
action='store_true',
help='Indent output of 4 spaces')
parser.add_argument( parser.add_argument(
'-d', '-d',
'--debug', '--debug',
@ -296,9 +317,11 @@ if __name__ == "__main__":
) )
try: try:
import black import black
mode = black.Mode(line_length=120) mode = black.Mode(line_length=args.line_length)
dict_str = black.format_str(repr(printer_config), mode=mode) dict_str = black.format_str(repr(printer_config), mode=mode)
print(dict_str)
except Exception: except Exception:
from pprint import pprint import pprint
pprint(printer_config) dict_str = pprint.pformat(printer_config)
if args.indent:
dict_str = textwrap.indent(dict_str, ' ')
print(dict_str)