Agregada la funcion de generar DB de Instancias
This commit is contained in:
parent
9f8437fc2d
commit
24cf3c670b
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "Procesador de XML exportado de TIA",
|
||||
"name": "Procesador de XML LAD-SCL-AWL exportado de TIA a SCL / Markdown",
|
||||
"description": "Conjunto de scripts que procesan archivos XML exportados de TIA, conviertiendo los objetos LAD a SCL y generando documentación en formato Markdown. ",
|
||||
"version": "1.0",
|
||||
"author": "Miguel"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -285,7 +285,8 @@ def convert_xml_to_json(xml_filepath, json_filepath):
|
|||
block_tag_name = etree.QName(the_block.tag).localname # Nombre del tag (ej. SW.Blocks.OB)
|
||||
block_type_map = {
|
||||
"SW.Blocks.FC": "FC", "SW.Blocks.FB": "FB",
|
||||
"SW.Blocks.GlobalDB": "GlobalDB", "SW.Blocks.OB": "OB"
|
||||
"SW.Blocks.GlobalDB": "GlobalDB", "SW.Blocks.OB": "OB",
|
||||
"SW.Blocks.InstanceDB": "InstanceDB" # <-- ADDED: Recognize InstanceDB
|
||||
}
|
||||
block_type_found = block_type_map.get(block_tag_name, "UnknownBlockType")
|
||||
print(f"Paso 2b: Bloque {block_tag_name} (Tipo: {block_type_found}) encontrado (ID={the_block.get('ID')}).")
|
||||
|
@ -306,7 +307,7 @@ def convert_xml_to_json(xml_filepath, json_filepath):
|
|||
lang_node = attr_list.xpath("./ProgrammingLanguage/text()")
|
||||
# Asignar lenguaje por defecto si no se encuentra
|
||||
block_lang_val = lang_node[0].strip() if lang_node else \
|
||||
("DB" if block_type_found == "GlobalDB" else "Unknown")
|
||||
("DB" if block_type_found in ["GlobalDB", "InstanceDB"] else "Unknown") # <-- MODIFIED: Include InstanceDB for DB language default
|
||||
print(f"Paso 3: Atributos: Nombre='{block_name_val}', Número={block_number_val}, Lenguaje Bloque='{block_lang_val}'")
|
||||
|
||||
# Extraer comentario del bloque (puede estar en AttributeList o ObjectList)
|
||||
|
@ -320,7 +321,7 @@ def convert_xml_to_json(xml_filepath, json_filepath):
|
|||
print(f"Paso 3b: Comentario bloque: '{block_comment_val[:50]}...'")
|
||||
else:
|
||||
print(f"Advertencia: No se encontró AttributeList para el bloque {block_type_found}.")
|
||||
if block_type_found == "GlobalDB": block_lang_val = "DB" # Default para DB
|
||||
if block_type_found in ["GlobalDB", "InstanceDB"]: block_lang_val = "DB" # Default para DB/InstanceDB # <-- MODIFIED: Include InstanceDB
|
||||
|
||||
# Inicializar diccionario de resultado para el bloque
|
||||
result = {
|
||||
|
@ -363,7 +364,7 @@ def convert_xml_to_json(xml_filepath, json_filepath):
|
|||
|
||||
|
||||
# --- Procesar Redes (CompileUnits) ---
|
||||
if block_type_found not in ["GlobalDB"]: # DBs no tienen redes ejecutables
|
||||
if block_type_found not in ["GlobalDB", "InstanceDB"]: # DBs/InstanceDBs no tienen redes ejecutables # <-- MODIFIED: Include InstanceDB
|
||||
print("Paso 5: Buscando y PROCESANDO redes (CompileUnits)...")
|
||||
networks_processed_count = 0
|
||||
result["networks"] = [] # Asegurar que esté inicializado
|
||||
|
@ -424,11 +425,10 @@ def convert_xml_to_json(xml_filepath, json_filepath):
|
|||
|
||||
if networks_processed_count == 0: print(f"Advertencia: ObjectList para {block_type_found} sin SW.Blocks.CompileUnit.")
|
||||
else: print(f"Advertencia: No se encontró ObjectList para el bloque {block_type_found}.")
|
||||
else: print("Paso 5: Saltando procesamiento de redes para GlobalDB.")
|
||||
else: print(f"Paso 5: Saltando procesamiento de redes para {block_type_found}.") # <-- MODIFIED: Updated message
|
||||
|
||||
else: # No se encontró ningún bloque SW.Blocks.*
|
||||
print("Error Crítico: No se encontró el elemento raíz del bloque (<SW.Blocks.FC/FB/GlobalDB/OB>) después de descartar UDT/TagTable.")
|
||||
return False
|
||||
print("Error Crítico: No se encontró el elemento raíz del bloque (<SW.Blocks.FC/FB/GlobalDB/OB/InstanceDB>) después de descartar UDT/TagTable.") # <-- MODIFIED: Updated message
|
||||
# --- Fin del manejo de Bloques ---
|
||||
|
||||
# --- Escritura del JSON Final ---
|
||||
|
@ -440,7 +440,7 @@ def convert_xml_to_json(xml_filepath, json_filepath):
|
|||
print("Paso 6: Escribiendo el resultado en el archivo JSON...")
|
||||
# Advertencias finales si faltan partes clave
|
||||
if result.get("block_type") not in ["PlcUDT", "PlcTagTable"] and not result.get("interface"): print("ADVERTENCIA FINAL: 'interface' está vacía en el JSON.")
|
||||
if result.get("block_type") not in ["PlcUDT", "PlcTagTable", "GlobalDB"] and not result.get("networks"): print("ADVERTENCIA FINAL: 'networks' está vacía en el JSON.")
|
||||
if result.get("block_type") not in ["PlcUDT", "PlcTagTable", "GlobalDB", "InstanceDB"] and not result.get("networks"): print("ADVERTENCIA FINAL: 'networks' está vacía en el JSON.") # <-- MODIFIED: Include InstanceDB
|
||||
|
||||
# Escribir el archivo JSON
|
||||
try:
|
||||
|
|
|
@ -275,7 +275,7 @@ def process_json_to_scl(json_filepath, output_json_filepath):
|
|||
block_type = data.get("block_type", "Unknown")
|
||||
print(f"Procesando bloque tipo: {block_type}")
|
||||
|
||||
if block_type in ["GlobalDB", "PlcUDT", "PlcTagTable"]:
|
||||
if block_type in ["GlobalDB", "PlcUDT", "PlcTagTable", "InstanceDB"]: # <-- MODIFIED: Add InstanceDB
|
||||
print(f"INFO: El bloque es {block_type}. Saltando procesamiento lógico de x2.")
|
||||
print(
|
||||
f"Guardando JSON de {block_type} (con metadatos) en: {output_json_filepath}"
|
||||
|
|
|
@ -83,6 +83,11 @@ def generate_scl_or_markdown(
|
|||
generation_function = generate_scl_for_db
|
||||
func_args["project_root_dir"] = project_root_dir
|
||||
output_extension = ".scl"
|
||||
elif block_type == "InstanceDB": # <-- ADDED: Handle InstanceDB
|
||||
print(" -> Modo de generación: INSTANCE_DATA_BLOCK SCL")
|
||||
generation_function = generate_scl_for_db # Use the same generator as GlobalDB
|
||||
func_args["project_root_dir"] = project_root_dir
|
||||
output_extension = ".scl"
|
||||
elif block_type in ["FC", "FB", "OB"]:
|
||||
print(f" -> Modo de generación: {block_type} SCL")
|
||||
generation_function = generate_scl_for_code_block
|
||||
|
|
2368
data/log.txt
2368
data/log.txt
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue