Multi-Context¶
PiPLC supports up to 8 independent engine contexts per server. Each context is a complete virtual PLC with its own program, memory, and scan cycle.
Architecture¶
Server (EngineServer)
├── EngineContext "PLC1" (ExecutionEngine + MemoryManager + Program)
├── EngineContext "PLC2" (ExecutionEngine + MemoryManager + Program)
├── EngineContext "PLC3" ...
└── SignalRouter (inter-context communication)
Managing Contexts¶
Use the Engine Selector in the toolbar:
- Create context: Click "+" → enter a name
- Select context: Use the dropdown to switch the active context
- Delete context: Click "x" (requires engine to be stopped)
When switching contexts:
- The current editor state is saved (program, file, watch list)
- The target context's state is restored
- Each context has its own independent ladder editor
Saving Multi-Context Projects¶
The .mplcproj format saves all contexts in a single file, including:
- Programs for each context
- Signal Router routes
- The active context at save time
Tip
Use multi-context to simulate entire production lines — each context can represent a different station or controller.
Remote Engine Connections¶
The editor can connect to remote piplc-engine instances running on other machines (e.g., Raspberry Pi). Remote contexts appear as additional tabs alongside local contexts.
Connecting to a Remote Engine¶
- Use Engine > Connect to Remote Engine or the connection toolbar
- Enter the server URL (e.g.,
ws://192.168.1.50:9100) - Select a context from the available list
- The remote context tab appears in the editor
Disconnecting¶
Right-click a remote context tab and select Disconnect to detach from the remote engine without stopping the running program. This is useful for monitoring without disrupting execution.
Warning
If signal routes reference the context being disconnected, a warning is shown. Disconnecting will break those routes until reconnection.
Project Configuration¶
The Project Configuration dialog (Tools > Project Configuration) lets you configure project-level settings that are saved with the .plcproj or .mplcproj file.
HMI File Association¶
- Set an HMI file path (
.hmi) to automatically open alongside the project - When a project with an associated HMI file is opened, the HMI window launches automatically
Remote Connection Persistence¶
- Save current connection with project — stores the remote server URL, port, and context ID/name in the project file
- On next project open, PiPLC automatically attempts to reconnect to the saved server and context
When auto-connecting, if both the project file and the remote engine have programs, a program conflict dialog appears:
| Option | Behavior |
|---|---|
| Use engine's program | Keeps the program currently running on the remote engine |
| Download project's program | Uploads the project file's program to the engine, replacing its current program |
This ensures you always know which program is active after connecting.
Tip
Remote connection persistence is ideal for production setups — save your project once with the connection info, and it reconnects automatically every time you open it.
See Also¶
- Signal Router — inter-context communication
- Deployment Modes — remote engine deployment scenarios
- HMI — HMI independent context selection