feat: Update workspace paths and enhance JSON output handling with relative paths for better portability
This commit is contained in:
parent
480e831b7a
commit
f7d11c67c3
|
@ -5,7 +5,7 @@
|
||||||
"path": "."
|
"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": {
|
"settings": {
|
||||||
|
|
|
@ -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
|
target_scl = format_variable_name(plc_name) # Use existing util
|
||||||
else:
|
else:
|
||||||
print(f"Error: Target variable for {instr_uid}.{pin_name} has no name (UID: {target_info.get('uid')}).")
|
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":
|
elif target_info.get("type") == "constant":
|
||||||
print(f"Advertencia: Attempt to write to constant target {instr_uid}.{pin_name} (UID: {target_info.get('uid')}).")
|
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
|
# else: # Handle other target types if needed
|
||||||
|
|
|
@ -646,8 +646,13 @@ def convert_xml_to_json(xml_filepath, json_filepath):
|
||||||
with open(json_filepath, "w", encoding="utf-8") as f:
|
with open(json_filepath, "w", encoding="utf-8") as f:
|
||||||
json.dump(result, f, indent=4, ensure_ascii=False)
|
json.dump(result, f, indent=4, ensure_ascii=False)
|
||||||
print("Paso 6: Escritura JSON completada.")
|
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(
|
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
|
return True # Indicar éxito
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
|
|
|
@ -126,8 +126,13 @@ def generate_scl_or_markdown(
|
||||||
# El 'final_output_directory' ya viene calculado desde __main__
|
# El 'final_output_directory' ya viene calculado desde __main__
|
||||||
output_filepath = os.path.join(final_output_directory, output_filename_base)
|
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(
|
print(
|
||||||
f" -> Escribiendo archivo de salida final en: {os.path.relpath(output_filepath)}"
|
f" -> Escribiendo archivo de salida final en: {rel_path}"
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
# Asegurar que el directorio de salida exista (ya debería estar hecho en __main__)
|
# Asegurar que el directorio de salida exista (ya debería estar hecho en __main__)
|
||||||
|
|
Loading…
Reference in New Issue