Refinements

This commit is contained in:
Ircama 2023-08-04 18:45:54 +02:00
parent 5c995f1f84
commit 14c1f536c6
2 changed files with 48 additions and 14 deletions

View file

@ -169,10 +169,10 @@ Example of advanced printer status with an XP-205 printer:
'last_printer_fatal_errors': ['08', 'F1', 'F1', 'F1', 'F1', '10'], 'last_printer_fatal_errors': ['08', 'F1', 'F1', 'F1', 'F1', '10'],
'printer_head_id': '...', 'printer_head_id': '...',
'printer_status': {'cancel_code': 'No request', 'printer_status': {'cancel_code': 'No request',
'ink_level': [(1, 89, 'Black'), 'ink_level': [(1, 0, 'Black', 'Black', 89),
(5, 77, 'Yellow'), (5, 3, 'Yellow', 'Yellow', 77),
(4, 59, 'Magenta'), (4, 2, 'Magenta', 'Magenta', 59),
(3, 40, 'Cyan')], (3, 1, 'Cyan', 'Cyan', 40)],
'jobname': 'Not defined', 'jobname': 'Not defined',
'loading_path': 'fixed', 'loading_path': 'fixed',
'maintenance_box_0': 'not full (0)', 'maintenance_box_0': 'not full (0)',

View file

@ -542,6 +542,15 @@ class EpsonPrinter:
0x11: 'Green', 0x11: 'Green',
} }
ink_color_ids = {
0x00: 'Black',
0x01: 'Cyan',
0x02: 'Magenta',
0x03: 'Yellow',
0x04: 'Light Cyan',
0x05: 'Light Magenta',
}
status_ids = { status_ids = {
0: 'Error', 0: 'Error',
1: 'Self Printing', 1: 'Self Printing',
@ -556,7 +565,12 @@ class EpsonPrinter:
if len(data) < 16: if len(data) < 16:
return "invalid packet" return "invalid packet"
if data[:11] != b'\x00@BDC ST2\r\n': if data[:11] != b'\x00@BDC ST2\r\n':
return "printer status error" if self.debug:
print("Unaligned BDC ST2 header. Trying to fix...")
start = data.find(b'BDC ST2\r\n')
if start < 0:
return "printer status error (must start with BDC ST2...)"
data = bytes(2) + data[start:]
len_p = int.from_bytes(data[11:13], byteorder='little') len_p = int.from_bytes(data[11:13], byteorder='little')
if len(data) - 13 != len_p: if len(data) - 13 != len_p:
return "message error" return "message error"
@ -606,14 +620,19 @@ class EpsonPrinter:
data_set["paper_path"] = "Cut sheet (Rear)" data_set["paper_path"] = "Cut sheet (Rear)"
elif ftype == 0x0d: # maintenance tanks elif ftype == 0x0d: # maintenance tanks
print("ALBE", item)
data_set["tanks"] = str([i for i in item]) data_set["tanks"] = str([i for i in item])
elif ftype == 0x0e: # Replace cartridge information
data_set["replace_cartridge"] = "{:08b}".format(item[0])
elif ftype == 0x0f: # ink elif ftype == 0x0f: # ink
colourlen = item[0] colourlen = item[0]
offset = 1 offset = 1
inks = [] inks = []
while offset < length: while offset < length:
colour = item[offset] colour = item[offset]
ink_color = item[offset + 1]
level = item[offset + 2] level = item[offset + 2]
offset += colourlen offset += colourlen
@ -622,13 +641,15 @@ class EpsonPrinter:
else: else:
name = "0x%X" % colour name = "0x%X" % colour
inks.append((colour, level, name)) if ink_color in ink_color_ids:
ink_name = ink_color_ids[ink_color]
else:
ink_name = "0x%X" % ink_color
inks.append((colour, ink_color, name, ink_name, level))
data_set["ink_level"] = inks data_set["ink_level"] = inks
elif ftype == 0x0e: # Replace cartridge information
data_set["replace_cartridge"] = "{:08b}".format(item[0])
elif ftype == 0x10: # Loading path information elif ftype == 0x10: # Loading path information
data_set["loading_path"] = item.hex().upper() data_set["loading_path"] = item.hex().upper()
if data_set["loading_path"] == "01094E": if data_set["loading_path"] == "01094E":
@ -654,8 +675,12 @@ class EpsonPrinter:
data_set["serial"] = str(item) data_set["serial"] = str(item)
elif ftype == 0x37: # Maintenance box information elif ftype == 0x37: # Maintenance box information
i = 1 num_bytes = item[0]
for j in range(item[0]): if num_bytes < 1 or num_bytes > 2:
data_set["maintenance_box"] = "unknown"
continue
j = 1
for i in range(1, length, num_bytes):
if item[i] == 0: if item[i] == 0:
data_set[f"maintenance_box_{j}"] = ( data_set[f"maintenance_box_{j}"] = (
f"not full ({item[i]})" f"not full ({item[i]})"
@ -672,7 +697,16 @@ class EpsonPrinter:
data_set[f"maintenance_box_{j}"] = ( data_set[f"maintenance_box_{j}"] = (
f"unknown ({item[i]})" f"unknown ({item[i]})"
) )
i += (len(item) - 1) // 2 if num_bytes > 1:
data_set[f"maintenance_box_reset_count_{j}"] = item[
i + 1]
j += 1
elif ftype == 0x40: # Serial No. information
try:
data_set["serial_number_info"] = item.decode()
except Exception:
data_set["serial_number_info"] = str(item)
else: # unknown stuff else: # unknown stuff
if "unknown" not in data_set: if "unknown" not in data_set:
@ -732,7 +766,7 @@ class EpsonPrinter:
total = (total << 8) + int(val, 16) total = (total << 8) + int(val, 16)
stats_result[stat_name] = total stats_result[stat_name] = total
if "First TI received time" not in stats_result: if "First TI received time" not in stats_result:
return None return stats_result
ftrt = stats_result["First TI received time"] ftrt = stats_result["First TI received time"]
year = 2000 + ftrt // (16 * 32) year = 2000 + ftrt // (16 * 32)
month = (ftrt - (year - 2000) * (16 * 32)) // 32 month = (ftrt - (year - 2000) * (16 * 32)) // 32