API & MCP
Everything a person can do on Twinworks PLC Scan Simulator, a program or AI agent can do with the same inputs and get the identical result.
HTTP API
POST https://twinworksplcsimulator.usefulweb.app/api/v1/calculate– run Twinworks PLC Scan SimulatorGET https://twinworksplcsimulator.usefulweb.app/api/v1/tool– inputs, output schema, examples- OpenAPI 3.1: /openapi.json · /openapi.yaml
- Errors:
application/problem+json;422includes per-fielderrors.
Twinworks PLC Scan Simulator
Run a small PLC program in a simulated scan cycle: an IEC 61131-3 style Structured Text subset, a ladder diagram in text form or a state machine. Inputs change on a timeline; every scan reads inputs, executes the program and writes outputs. You get the output and state timeline, TON/TOF/TP timers and CTU/CTD counters per standard behaviour, the generated Structured Text and a timing diagram. Simulation only, no real PLC I/O.
| Field | Type | Default | Description |
|---|---|---|---|
language | select (st, ladder, statemachine) | "st" | Language |
program | textarea | "PROGRAM Timers\nVAR_INPUT\n Button : BOOL;\nEND_VAR\nVAR_OUTPUT\n OnDelay, Of | Program. Structured Text: VAR_INPUT / VAR_OUTPUT / VAR blocks (BOOL, INT, DINT, REAL, TIME, TON, TOF, TP, CTU, CTD, CTUD, R_TRIG, F_TRIG, SR, RS), IF/ELSIF/ELSE, CASE, FOR, WHILE, REPEAT, := assignments, PLC_TIME. Ladder: one rung per line, "(Start | Motor) & !Stop -> Motor", outputs Name, !Name, S Name, R Name, TON T1 PT=T#5s, CTU C1 PV=3 R=Reset; POS(x)/NEG(x) edge contacts. State machine: input/output/var lines, "state Name [initial]", entry/do/exit statements, "transition A -> B when GUARD", StateTime. |
timeline | textarea | "0 Button=0\n100ms Button=1\n200ms Button=0\n400ms Button=1\n1000ms Button=0\n11 | Input timeline. One line per time: time then Name=value pairs, e.g. "0 Start=0", "250ms Start=1", "2s Stop=TRUE". Times in ms unless s/m/h or T#… is given. Inputs keep their value until changed. |
cycleMs | integer | 10 | Scan cycle time |
durationMs | integer | 1500 | Duration |
watch | text | — | Extra variables to trace (optional). Comma-separated, e.g. T1.ET, Count. Inputs, outputs, timer Q and counter CV are always traced. |
Example request
TON, TOF, TP and CTU on one push button
curl -X POST https://twinworksplcsimulator.usefulweb.app/api/v1/calculate -H 'content-type: application/json' -d '{"language":"st","program":"PROGRAM Timers\nVAR_INPUT\n Button : BOOL;\nEND_VAR\nVAR_OUTPUT\n OnDelay, OffDelay, Pulse : BOOL;\n Presses : INT;\nEND_VAR\nVAR\n T1 : TON; T2 : TOF; T3 : TP; C1 : CTU;\nEND_VAR\nT1(IN := Button, PT := T#300ms);\nT2(IN := Button, PT := T#300ms);\nT3(IN := Button, PT := T#300ms);\nC1(CU := Button, R := FALSE, PV := 3);\nOnDelay := T1.Q;\nOffDelay := T2.Q;\nPulse := T3.Q;\nPresses := C1.CV;\nEND_PROGRAM","timeline":"0 Button=0\n100ms Button=1\n200ms Button=0\n400ms Button=1\n1000ms Button=0\n1100ms Button=1\n1150ms Button=0","cycleMs":10,"durationMs":1500}'
Every result contains
inputs (normalised, defaults applied), summary, result (validated against the published schema), units, assumptions, sources, warnings, computedAt and links.
MCP (Model Context Protocol)
- Streamable HTTP endpoint:
https://twinworksplcsimulator.usefulweb.app/mcp– protocol revisions 2026-07-28 (stateless) and 2025-11-25 / 2025-06-18 / 2025-03-26 (initialize handshake). - Tools:
twinworks_plc_simulator - Local stdio connector:
node src/mcp-stdio.ts --tool=twinworks-plc-simulator
{
"mcpServers": {
"twinworks-plc-simulator": { "type": "http", "url": "https://twinworksplcsimulator.usefulweb.app/mcp" }
}
}