diff --git a/backend/script_groups/XML Parser to SCL/XML Parser to SCL.code-workspace b/backend/script_groups/XML Parser to SCL/XML Parser to SCL.code-workspace index 4dad223..f62d4eb 100644 --- a/backend/script_groups/XML Parser to SCL/XML Parser to SCL.code-workspace +++ b/backend/script_groups/XML Parser to SCL/XML Parser to SCL.code-workspace @@ -5,7 +5,7 @@ "path": "." }, { - "path": "../../../../../../Trabajo/VM/45 - HENKEL - VM Auto Changeover/ExportTia" + "path": "C:/Trabajo/SIDEL/09 - SAE452 - Diet as Regular - San Giorgio in Bosco/ExportTia/CPU_315F-2_PN_DP" } ], "settings": { diff --git a/backend/script_groups/XML Parser to SCL/processors/processor_utils.py b/backend/script_groups/XML Parser to SCL/processors/processor_utils.py index c231787..c209276 100644 --- a/backend/script_groups/XML Parser to SCL/processors/processor_utils.py +++ b/backend/script_groups/XML Parser to SCL/processors/processor_utils.py @@ -320,6 +320,42 @@ def get_target_scl_name(instruction, pin_name, network_id, default_to_temp=True) target_scl = format_variable_name(plc_name) # Use existing util else: print(f"Error: Target variable for {instr_uid}.{pin_name} has no name (UID: {target_info.get('uid')}).") + elif target_info.get("type") == "unknown_structure": + # Handle direct memory addresses like DB960.X448.0 + area = target_info.get("Area") + block_number = target_info.get("BlockNumber") + bit_offset = target_info.get("BitOffset") + data_type = target_info.get("Type") + + if area and block_number and bit_offset is not None: + if area == "DB" and data_type == "Bool": + # Convert bit offset to byte and bit + byte_offset = int(bit_offset) // 8 + bit_pos = int(bit_offset) % 8 + target_scl = f"%DB{block_number}.DBX{byte_offset}.{bit_pos}" + elif area == "DB" and data_type in ["Word", "Int"]: + byte_offset = int(bit_offset) // 8 + target_scl = f"%DB{block_number}.DBW{byte_offset}" + elif area == "DB" and data_type in ["DWord", "DInt", "Real"]: + byte_offset = int(bit_offset) // 8 + target_scl = f"%DB{block_number}.DBD{byte_offset}" + else: + # Other area types (M, I, Q, etc.) + if data_type == "Bool": + byte_offset = int(bit_offset) // 8 + bit_pos = int(bit_offset) % 8 + target_scl = f"%{area}{byte_offset}.{bit_pos}" + else: + byte_offset = int(bit_offset) // 8 + if data_type in ["Word", "Int"]: + target_scl = f"%{area}W{byte_offset}" + elif data_type in ["DWord", "DInt", "Real"]: + target_scl = f"%{area}D{byte_offset}" + else: + target_scl = f"%{area}{byte_offset}" + print(f"INFO: Converted direct address to SCL: {target_scl} for {instr_uid}.{pin_name}") + else: + print(f"Error: Incomplete address info for {instr_uid}.{pin_name}: Area={area}, Block={block_number}, Offset={bit_offset}") elif target_info.get("type") == "constant": print(f"Advertencia: Attempt to write to constant target {instr_uid}.{pin_name} (UID: {target_info.get('uid')}).") # else: # Handle other target types if needed diff --git a/backend/script_groups/XML Parser to SCL/x1_to_json.py b/backend/script_groups/XML Parser to SCL/x1_to_json.py index 7a70acb..2a48cb0 100644 --- a/backend/script_groups/XML Parser to SCL/x1_to_json.py +++ b/backend/script_groups/XML Parser to SCL/x1_to_json.py @@ -646,8 +646,13 @@ def convert_xml_to_json(xml_filepath, json_filepath): with open(json_filepath, "w", encoding="utf-8") as f: json.dump(result, f, indent=4, ensure_ascii=False) print("Paso 6: Escritura JSON completada.") + try: + rel_path = os.path.relpath(json_filepath) + except ValueError: + # Fallback si relpath falla con diferentes unidades + rel_path = json_filepath print( - f"Conversión finalizada. JSON guardado en: '{os.path.relpath(json_filepath)}'" + f"Conversión finalizada. JSON guardado en: '{rel_path}'" ) return True # Indicar éxito except IOError as e: diff --git a/backend/script_groups/XML Parser to SCL/x3_generate_scl.py b/backend/script_groups/XML Parser to SCL/x3_generate_scl.py index dad17c2..027cb8d 100644 --- a/backend/script_groups/XML Parser to SCL/x3_generate_scl.py +++ b/backend/script_groups/XML Parser to SCL/x3_generate_scl.py @@ -126,8 +126,13 @@ def generate_scl_or_markdown( # El 'final_output_directory' ya viene calculado desde __main__ output_filepath = os.path.join(final_output_directory, output_filename_base) + try: + rel_path = os.path.relpath(output_filepath) + except ValueError: + # Fallback si relpath falla con diferentes unidades + rel_path = output_filepath print( - f" -> Escribiendo archivo de salida final en: {os.path.relpath(output_filepath)}" + f" -> Escribiendo archivo de salida final en: {rel_path}" ) try: # Asegurar que el directorio de salida exista (ya debería estar hecho en __main__)