From c3fd25c223c7b75fb355019cf2d703b9c8819985 Mon Sep 17 00:00:00 2001 From: Ircama Date: Sat, 5 Aug 2023 17:05:09 +0200 Subject: [PATCH] Refinements --- README.md | 27 +++++++++++++++++-- epson_print_conf.py | 63 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 77 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7d49234..b4ec76f 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,27 @@ TimeoutError Example of advanced printer status with an XP-205 printer: ``` -{'cartridges': ['18XL', '18XL', '18XL', '18XL'], +{'cartridge_information': [{'id': '0D081F172A0D04004C', + 'ink_color': 'Black', + 'ink_quantity': 89, + 'production_month': 8, + 'production_year': 2013}, + {'id': '15031D06230D080093', + 'ink_color': 'Yellow', + 'ink_quantity': 77, + 'production_month': 3, + 'production_year': 2021}, + {'id': '150317111905020047', + 'ink_color': 'Magenta', + 'ink_quantity': 59, + 'production_month': 3, + 'production_year': 2021}, + {'id': '14091716080501001D', + 'ink_color': 'Cyan', + 'ink_quantity': 40, + 'production_month': 9, + 'production_year': 2020}], + 'cartridges': ['18XL', '18XL', '18XL', '18XL'], 'firmware_version': 'RF11I5 11 May 2018', 'ink_replacement_counters': {('Black', '1B', 1), ('Black', '1L', 19), @@ -175,8 +195,10 @@ Example of advanced printer status with an XP-205 printer: (3, 1, 'Cyan', 'Cyan', 40)], 'jobname': 'Not defined', 'loading_path': 'fixed', - 'maintenance_box_0': 'not full (0)', 'maintenance_box_1': 'not full (0)', + 'maintenance_box_2': 'not full (0)', + 'maintenance_box_reset_count_1': 0, + 'maintenance_box_reset_count_2': 0, 'paper_path': 'Cut sheet (Rear)', 'ready': True, 'replace_cartridge': '00000001', @@ -190,6 +212,7 @@ Example of advanced printer status with an XP-205 printer: 'Emulation 3': 'BDC', 'Emulation 4': 'other', 'Emulation 5': 'other', + 'Epson Model': 'XP-205 207 Series', 'IP Address': '192.168.1.87', 'Lang 1': 'unknown', 'Lang 2': 'ESCPL2', diff --git a/epson_print_conf.py b/epson_print_conf.py index 015a8c1..65fb003 100644 --- a/epson_print_conf.py +++ b/epson_print_conf.py @@ -277,6 +277,7 @@ class EpsonPrinter: snmp_info = { "Model": "1.3.6.1.2.1.25.3.2.1.3.1", + "Epson Model": "1.3.6.1.4.1.1248.1.2.2.1.1.1.2.1", "Model short": "1.3.6.1.4.1.1248.1.1.3.1.3.8.0", "EEPS2 firmware version": "1.3.6.1.2.1.2.2.1.2.1", "Descr": "1.3.6.1.2.1.1.1.0", @@ -316,6 +317,15 @@ class EpsonPrinter: hostname: str parm: dict + ink_color_ids = { # Ink color + 0x00: 'Black', + 0x01: 'Cyan', + 0x02: 'Magenta', + 0x03: 'Yellow', + 0x04: 'Light Cyan', + 0x05: 'Light Magenta', + } + def __init__( self, printer_model: @@ -570,15 +580,6 @@ class EpsonPrinter: 0x11: 'Green', } - ink_color_ids = { # Ink color - 0x00: 'Black', - 0x01: 'Cyan', - 0x02: 'Magenta', - 0x03: 'Yellow', - 0x04: 'Light Cyan', - 0x05: 'Light Magenta', - } - status_ids = { 0x00: 'Error', 0x01: 'Self Printing', @@ -728,8 +729,8 @@ class EpsonPrinter: else: name = "0x%X" % colour - if ink_color in ink_color_ids: - ink_name = ink_color_ids[ink_color] + if ink_color in self.ink_color_ids: + ink_name = self.ink_color_ids[ink_color] else: ink_name = "0x%X" % ink_color @@ -1041,6 +1042,46 @@ class EpsonPrinter: label="last_printer_fatal_errors" ) + def ink_color(self, number): + if number - 1811 in self.ink_color_ids: + return self.ink_color_ids[number - 1811] + else: + return number + + def get_cartridge_information(self) -> str: + """Return list of cartridge properties.""" + response = [] + for i in range(1, 9): + mib = f"{self.eeprom_link}.105.105.2.0.1." + str(i) + cartridge = self.snmp_mib(mib) + if cartridge.find(b'ii:NA;') > 0 or cartridge.find( + b'BDC PS\r\n') < 0: + break + if self.debug: + print( + f"Cartridge {i}:\n" + f" MIB: {mib}" + ) + if self.debug: + print(f" RESPONSE: {repr(cartridge)}") + response.append(cartridge[10:-2].decode().split(';')) + cartridges = [ + {i[0]: i[1] for i in map(lambda x: x.split(':'), j)} + for j in response + ] + return [ + { + "ink_color": self.ink_color(int(i['IC1'], 16)), + "ink_quantity": int(i['IQT'], 16), + #"viq": int(i['VIQ'], 16), + #"uiq": int(i['UIQ'], 16), + "production_year": int(i['PDY'], 16) + ( + 1900 if int(i['PDY'], 16) > 80 else 2000), + "production_month": int(i['PDM'], 16), + "id": i['SID'] + } for i in cartridges + ] + def dump_eeprom(self, start: int = 0, end: int = 0xFF): """ Dump EEPROM data from start to end (less significant byte).