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

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.

Inputs of Twinworks PLC Scan Simulator
FieldTypeDefaultDescription
languageselect (st, ladder, statemachine)"st"Language
programtextarea"PROGRAM Timers\nVAR_INPUT\n Button : BOOL;\nEND_VAR\nVAR_OUTPUT\n OnDelay, OfProgram. 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.
timelinetextarea"0 Button=0\n100ms Button=1\n200ms Button=0\n400ms Button=1\n1000ms Button=0\n11Input 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.
cycleMsinteger10Scan cycle time
durationMsinteger1500Duration
watchtext—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)

{
  "mcpServers": {
    "twinworks-plc-simulator": { "type": "http", "url": "https://twinworksplcsimulator.usefulweb.app/mcp" }
  }
}