How the TwinCAT state is controlled

TwinCAT can be set to Config mode using DTE commands; the FreeRun state can be toggled, and the current start state can be queried via the interface.

Requirements

C# sample

// Switch TwinCAT to config mode
dte.ExecuteCommand("TwinCAT.RestartTwinCATConfigMode");

// Switch TwinCAT to run mode
dte.ExecuteCommand("TwinCAT.RestartTwinCATSystem");

// Check if TwinCAT is started (config or run mode)
bool isRunning = sysManager.IsTwinCATStarted();

PowerShell sample

# Config mode
$dte.ExecuteCommand("TwinCAT.RestartTwinCATConfigMode")

# Toggle FreeRun
$dte.ExecuteCommand("TwinCAT.ToogleFreeRunState")

# Check status
$isRunning = $sysManager.IsTwinCATStarted()
Write-Host "TwinCAT läuft: $isRunning"
How the TwinCAT state is controlled 1:

The TwinCAT state can be controlled not only using the DTE commands shown here, but also directly via ADS (TwinCAT system service, ADS port 10000).

How the TwinCAT state is controlled 2:

IsTwinCATStarted() returns true when TwinCAT is running, regardless of whether it is in Config or Run Mode. The method thus checks whether a TwinCAT instance is currently running. It serves as a prerequisite for actions that require a running TwinCAT instance, such as an upload. The exact difference compared to a Run Mode test still needs to be verified. Switching to Config mode via RestartTwinCATConfigMode is an asynchronous process. For reliable automation, it is recommended to query the TwinCAT state via ADS port 10000 until the Config mode is confirmed.