Mejorado para Tia 19
This commit is contained in:
parent
e70852ecf1
commit
0488624d64
|
@ -0,0 +1,81 @@
|
||||||
|
{
|
||||||
|
"block_name": "FC General Lamp",
|
||||||
|
"block_number": 172,
|
||||||
|
"language": "LAD",
|
||||||
|
"block_type": "FC",
|
||||||
|
"block_comment": "",
|
||||||
|
"interface": {
|
||||||
|
"Return": [
|
||||||
|
{
|
||||||
|
"name": "Ret_Val",
|
||||||
|
"datatype": "Void",
|
||||||
|
"remanence": "NonRetain",
|
||||||
|
"accessibility": "Public",
|
||||||
|
"start_value": null,
|
||||||
|
"comment": null,
|
||||||
|
"children": [],
|
||||||
|
"array_elements": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"networks": [
|
||||||
|
{
|
||||||
|
"id": "4",
|
||||||
|
"title": "Lamp Alarm - Q.E. - Light Green",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "B",
|
||||||
|
"title": "Lamp Alarm - Q.E. - Light Red",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "12",
|
||||||
|
"title": "Lamp Alarm - Q.E. - Buzzer",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "19",
|
||||||
|
"title": "Lamp Alarm - Q.E. - Light Blue",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "20",
|
||||||
|
"title": "Lamp - Alarm Presence",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "27",
|
||||||
|
"title": "Light Signal Phased Stop Machine",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2E",
|
||||||
|
"title": "",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source_xml_mod_time": 1749751920.2702959,
|
||||||
|
"source_xml_size": 39346
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,81 @@
|
||||||
|
{
|
||||||
|
"block_name": "FC General Lamp",
|
||||||
|
"block_number": 172,
|
||||||
|
"language": "LAD",
|
||||||
|
"block_type": "FC",
|
||||||
|
"block_comment": "",
|
||||||
|
"interface": {
|
||||||
|
"Return": [
|
||||||
|
{
|
||||||
|
"name": "Ret_Val",
|
||||||
|
"datatype": "Void",
|
||||||
|
"remanence": "NonRetain",
|
||||||
|
"accessibility": "Public",
|
||||||
|
"start_value": null,
|
||||||
|
"comment": null,
|
||||||
|
"children": [],
|
||||||
|
"array_elements": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"networks": [
|
||||||
|
{
|
||||||
|
"id": "4",
|
||||||
|
"title": "Lamp Alarm - Q.E. - Light Green",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "B",
|
||||||
|
"title": "Lamp Alarm - Q.E. - Light Red",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "12",
|
||||||
|
"title": "Lamp Alarm - Q.E. - Buzzer",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "19",
|
||||||
|
"title": "Lamp Alarm - Q.E. - Light Blue",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "20",
|
||||||
|
"title": "Lamp - Alarm Presence",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "27",
|
||||||
|
"title": "Light Signal Phased Stop Machine",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2E",
|
||||||
|
"title": "",
|
||||||
|
"comment": "",
|
||||||
|
"language": "LAD",
|
||||||
|
"logic": [],
|
||||||
|
"error": "FlgNet not found inside NetworkSource or CompileUnit"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source_xml_mod_time": 1749751920.2702959,
|
||||||
|
"source_xml_size": 39346
|
||||||
|
}
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
@ -61,15 +61,19 @@ def parse_lad_fbd_network(network_element):
|
||||||
network_lang = lang_node_net[0].strip()
|
network_lang = lang_node_net[0].strip()
|
||||||
|
|
||||||
# --- Buscar FlgNet ---
|
# --- Buscar FlgNet ---
|
||||||
# Buscar NetworkSource y luego FlgNet (ambos usan namespace flg)
|
# Paso 1: localizar el nodo <NetworkSource> (sin importar namespace)
|
||||||
network_source_node = network_element.xpath(".//flg:NetworkSource", namespaces=ns)
|
network_source_node = network_element.xpath(".//*[local-name()='NetworkSource']")
|
||||||
|
|
||||||
flgnet = None
|
flgnet = None
|
||||||
if network_source_node:
|
if network_source_node:
|
||||||
flgnet_list = network_source_node[0].xpath("./flg:FlgNet", namespaces=ns)
|
# Buscar FlgNet dentro del NetworkSource
|
||||||
|
flgnet_list = network_source_node[0].xpath(".//*[local-name()='FlgNet']")
|
||||||
if flgnet_list:
|
if flgnet_list:
|
||||||
flgnet = flgnet_list[0]
|
flgnet = flgnet_list[0]
|
||||||
else: # Intentar buscar FlgNet directamente si no hay NetworkSource
|
|
||||||
flgnet_list = network_element.xpath(".//flg:FlgNet", namespaces=ns)
|
# Paso 2: si no se encontró, intentar buscar FlgNet directamente en el CompileUnit
|
||||||
|
if flgnet is None:
|
||||||
|
flgnet_list = network_element.xpath(".//*[local-name()='FlgNet']")
|
||||||
if flgnet_list:
|
if flgnet_list:
|
||||||
flgnet = flgnet_list[0]
|
flgnet = flgnet_list[0]
|
||||||
|
|
||||||
|
|
|
@ -478,3 +478,74 @@ def parse_interface_members(member_elements):
|
||||||
} # Guardar como dict simple si no hay comment
|
} # Guardar como dict simple si no hay comment
|
||||||
members_data.append(member_info)
|
members_data.append(member_info)
|
||||||
return members_data
|
return members_data
|
||||||
|
|
||||||
|
# --- NUEVA FUNCIÓN: Adaptación dinámica de namespaces ---
|
||||||
|
|
||||||
|
def adapt_namespaces(root):
|
||||||
|
"""Actualiza dinámicamente los valores en el diccionario global `ns` para que
|
||||||
|
coincidan con los namespaces reales presentes en el XML exportado por TIA.
|
||||||
|
|
||||||
|
Debe llamarse después de obtener la raíz (`root = tree.getroot()`). Si en el
|
||||||
|
XML aparecen nuevas versiones (p.ej. v6) de los URIs, esta función las
|
||||||
|
detectará y sobreescribirá las entradas correspondientes en `ns`.
|
||||||
|
"""
|
||||||
|
if root is None:
|
||||||
|
return # nada que hacer
|
||||||
|
|
||||||
|
detected = {}
|
||||||
|
|
||||||
|
# 1) Examinar los namespaces declarados en la raíz (cuando existan)
|
||||||
|
if hasattr(root, "nsmap") and root.nsmap:
|
||||||
|
for uri in root.nsmap.values():
|
||||||
|
if not uri or "siemens.com/automation" not in str(uri):
|
||||||
|
continue
|
||||||
|
_assign_uri_to_prefix(str(uri), detected)
|
||||||
|
|
||||||
|
# 2) Escaneo rápido por elementos clave si aún no hemos encontrado URIs
|
||||||
|
# Utilizamos búsquedas sin namespace (local-name) para localizar el primer
|
||||||
|
# elemento relevante y extraer su URI real.
|
||||||
|
|
||||||
|
# helper interno
|
||||||
|
|
||||||
|
def find_uri_by_localname(tag_local):
|
||||||
|
elem = root.xpath(f'//*[local-name()="{tag_local}"]')
|
||||||
|
if elem:
|
||||||
|
return etree.QName(elem[0]).namespace
|
||||||
|
return None
|
||||||
|
|
||||||
|
if "flg" not in detected or not detected.get("flg"):
|
||||||
|
flg_uri = find_uri_by_localname("FlgNet")
|
||||||
|
if flg_uri:
|
||||||
|
detected["flg"] = flg_uri
|
||||||
|
|
||||||
|
if "st" not in detected or not detected.get("st"):
|
||||||
|
st_uri = find_uri_by_localname("StructuredText")
|
||||||
|
if st_uri:
|
||||||
|
detected["st"] = st_uri
|
||||||
|
|
||||||
|
if "stl" not in detected or not detected.get("stl"):
|
||||||
|
stl_uri = find_uri_by_localname("StatementList")
|
||||||
|
if stl_uri:
|
||||||
|
detected["stl"] = stl_uri
|
||||||
|
|
||||||
|
if "iface" not in detected or not detected.get("iface"):
|
||||||
|
iface_uri = find_uri_by_localname("Sections")
|
||||||
|
if iface_uri and "/Interface/" in iface_uri:
|
||||||
|
detected["iface"] = iface_uri
|
||||||
|
|
||||||
|
if detected:
|
||||||
|
ns.update(detected)
|
||||||
|
|
||||||
|
|
||||||
|
# --- función auxiliar privada para adapt_namespaces ---
|
||||||
|
|
||||||
|
def _assign_uri_to_prefix(uri_str: str, out_dict: dict):
|
||||||
|
"""Asigna un URI concreto al prefijo adecuado en `out_dict`."""
|
||||||
|
if "/Interface/" in uri_str:
|
||||||
|
out_dict["iface"] = uri_str
|
||||||
|
elif "/NetworkSource/FlgNet/" in uri_str:
|
||||||
|
out_dict["flg"] = uri_str
|
||||||
|
elif "/NetworkSource/StructuredText/" in uri_str:
|
||||||
|
out_dict["st"] = uri_str
|
||||||
|
elif "/NetworkSource/StatementList/" in uri_str:
|
||||||
|
out_dict["stl"] = uri_str
|
||||||
|
|
|
@ -25,7 +25,7 @@ from backend.script_utils import load_configuration
|
||||||
|
|
||||||
# Importar funciones comunes y namespaces desde el nuevo módulo de utils
|
# Importar funciones comunes y namespaces desde el nuevo módulo de utils
|
||||||
try:
|
try:
|
||||||
from parsers.parser_utils import ns, get_multilingual_text, parse_interface_members
|
from parsers.parser_utils import ns, get_multilingual_text, parse_interface_members, adapt_namespaces
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
print(
|
print(
|
||||||
f"Error crítico: No se pudieron importar funciones desde parsers.parser_utils: {e}"
|
f"Error crítico: No se pudieron importar funciones desde parsers.parser_utils: {e}"
|
||||||
|
@ -253,6 +253,11 @@ def convert_xml_to_json(xml_filepath, json_filepath):
|
||||||
parser = etree.XMLParser(remove_blank_text=True, recover=True)
|
parser = etree.XMLParser(remove_blank_text=True, recover=True)
|
||||||
tree = etree.parse(xml_filepath, parser)
|
tree = etree.parse(xml_filepath, parser)
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
# Ajustar namespaces dinámicamente para soportar distintas versiones de TIA
|
||||||
|
try:
|
||||||
|
adapt_namespaces(root)
|
||||||
|
except Exception as e_ns:
|
||||||
|
print(f"Advertencia: No se pudo adaptar namespaces dinámicamente: {e_ns}")
|
||||||
print("Paso 1: Parseo XML completado.")
|
print("Paso 1: Parseo XML completado.")
|
||||||
|
|
||||||
result = None
|
result = None
|
||||||
|
|
31534
data/log.txt
31534
data/log.txt
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue