Two issues caught when Karstein noted suppression wasn't actually working:
1. Wrong API. The script was setting:
script_engine.system.script_prompt_handling = ScriptPromptHandling.NoFlag
but ScriptPromptHandling has no 'NoFlag' member (it's 'SuppressPrompts'),
AND script_prompt_handling is a read-only property -- the settable one
is the obsolete-but-still-functional 'prompt_handling' (with the
obsolete PromptHandling enum, where PromptHandling.NONE = 0 is
documented as equivalent to ScriptPromptHandling.SuppressPrompts).
The bare AttributeError was silently swallowed by try/except so prompts
stayed forwarded to UI -> intermittent code-1 crashes when the storage
format dialog popped.
Fix: set system.prompt_handling = PromptHandling.NONE, with int-literal
fallback if the enum import doesn't resolve. Log when neither works.
2. After-swap stale state. Even after a successful update() that preserves
the device subtree, CODESYS keeps the OLD device's library version
pins in its in-memory project model. compile_project then errors with
'Could not open library IoStandard, 3.1.3.1 (System)'
'Device description for PLCWinNT is missing'
Fix: project.close() at the end of create_project (drops in-memory
state) + delete the precompilecache file. The next MCP tool call's
ensure_project_open reopens fresh against the swapped XML and compile
is clean.
Live verified on SP22 P1:
- create_project WinV3Test deviceName='CODESYS Control Win V3 x64'
-> succeeds, no UI dialog, project saved + closed.
- compile_project (first call after creation) -> 0 errors, 0 warnings.
- create_pou Application/FB_Counter + set_pou_code with real ST.
- PLC_PRG references FB_Counter.
- compile_project -> 0 errors, 0 warnings.
Co-authored-by: Karstein Phobic Nyvold Kvistad <karstein.kvistad@maritimerobotics.com>