积累修改;
This commit is contained in:
@@ -429,14 +429,20 @@ def display_data(address: int, data: bytes, modbus_map: dict=modbus_map) -> dict
|
||||
|
||||
def print_display(output_data: dict):
|
||||
""" 格式化表示输出数据 """
|
||||
bank_chars = ' \t\000'
|
||||
print("Parse Result:")
|
||||
label_len_max = max(map(lambda x: len(x[0]), output_data.values()))
|
||||
data_len_max = max(map(lambda x: len(str(x[1])), output_data.values()))
|
||||
for key, value in output_data.items():
|
||||
label = value[0]
|
||||
data = "-".join(map(str, value[1])) if type(value) == list else value[1]
|
||||
print(f"{tools.ByteConv.display_hex(key, 4)}: {data:<{data_len_max}} {label:<{label_len_max}}")
|
||||
|
||||
match value:
|
||||
case (str() as label, list() as data):
|
||||
print(f"{tools.ByteConv.display_hex(key, 4)}: {'-'.join(map(str, data)):<{data_len_max}} {label:<{label_len_max}}")
|
||||
case (str() as label, str() as data):
|
||||
print(f"{tools.ByteConv.display_hex(key, 4)}: {data.rstrip(bank_chars):<{data_len_max}} {label:<{label_len_max}}")
|
||||
case (str() as label, data):
|
||||
print(f"{tools.ByteConv.display_hex(key, 4)}: {data:<{data_len_max}} {label:<{label_len_max}}")
|
||||
case _:
|
||||
raise ValueError(f"Key: {key}, Unkown Value: {value}")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user