- Phase 1: Structured compiler diagnostics — compile_project now returns parsed errors/warnings with object name and line number; new get_compile_messages tool reads last build messages without recompiling - Phase 2: Project authoring — create_dut, create_gvl, create_folder, delete_object, rename_object, get_all_pou_code - Phase 3: Online/runtime — connect_to_device, disconnect_from_device, get_application_state, read_variable, write_variable, download_to_device, start_stop_application (with ensure_online_connection helper) - Phase 4: Library management — list_project_libraries, add_library - Bump version to 0.4.0, update README with full tool reference Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
import sys, scriptengine as script_engine, os, traceback
|
|
|
|
APP_ACTION = "{APP_ACTION}"
|
|
|
|
try:
|
|
print("DEBUG: start_stop_application script: Action='%s', Project='%s'" % (APP_ACTION, PROJECT_FILE_PATH))
|
|
primary_project = ensure_project_open(PROJECT_FILE_PATH)
|
|
if not APP_ACTION: raise ValueError("Action empty.")
|
|
|
|
action_lower = APP_ACTION.lower()
|
|
if action_lower not in ('start', 'stop'):
|
|
raise ValueError("Invalid action '%s'. Must be 'start' or 'stop'." % APP_ACTION)
|
|
|
|
online_app, target_app = ensure_online_connection(primary_project)
|
|
app_name = getattr(target_app, 'get_name', lambda: "Unknown")()
|
|
|
|
if action_lower == 'start':
|
|
if hasattr(online_app, 'start'):
|
|
print("DEBUG: Calling start()...")
|
|
online_app.start()
|
|
print("DEBUG: Application started.")
|
|
else:
|
|
raise TypeError("Online application does not support start().")
|
|
else:
|
|
if hasattr(online_app, 'stop'):
|
|
print("DEBUG: Calling stop()...")
|
|
online_app.stop()
|
|
print("DEBUG: Application stopped.")
|
|
else:
|
|
raise TypeError("Online application does not support stop().")
|
|
|
|
# Get state after action
|
|
state = "unknown"
|
|
if hasattr(online_app, 'application_state'):
|
|
try:
|
|
state = str(online_app.application_state)
|
|
except Exception:
|
|
pass
|
|
|
|
print("Action: %s" % APP_ACTION)
|
|
print("Application: %s" % app_name)
|
|
print("State After: %s" % state)
|
|
print("SCRIPT_SUCCESS: Application %s executed successfully." % action_lower)
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
detailed_error = traceback.format_exc()
|
|
error_message = "Error executing %s for project %s: %s\n%s" % (APP_ACTION, PROJECT_FILE_PATH, e, detailed_error)
|
|
print(error_message)
|
|
print("SCRIPT_ERROR: %s" % error_message)
|
|
sys.exit(1)
|