AI SCL Code Generator for Siemens TIA Portal
SCLcode is an AI code generator built only for Siemens Structured Control Language (SCL). You describe what a block should do, choose the PLC family, and get a complete FUNCTION_BLOCK or FUNCTION that you can import into TIA Portal as an external source.
General chatbots often write IEC Structured Text that does not compile in TIA Portal. SCLcode is tuned for Siemens syntax and checks every generated block before you see it.
How the AI SCL generator works
- Describe the block. For example: "Motor starter with start/stop, thermal overload, a 5 second star-delta changeover and a fault output for the HMI."
- Pick the target. Choose S7-1500, S7-1200 or S7-300/400 so the generator only uses data types and instructions that exist on that family.
- Review the result. The block comes with a commented interface (
VAR_INPUT,VAR_OUTPUT,VAR), a block view of the pins and a validation report. - Import into TIA Portal. Download the
.sclfile and use *Generate blocks from source*. The import guide walks through every step.
Why Siemens-specific matters
SCL is Siemens' implementation of IEC 61131-3 Structured Text, but the details differ from CODESYS or Rockwell. Code that ignores them fails to compile or, worse, behaves differently on the PLC. SCLcode is built around the Siemens rules:
- Timers are multi-instance IEC timers such as
TON_TIMEdeclared inVAR, never invented functions likeTIME()orDT_NOW(), which do not exist in SCL. - The PLC clock is read with
RD_SYS_T, not with aNOW()call. - Local variables use the
#prefix and block names are quoted, exactly as TIA Portal exports them. - S7-300/400 targets avoid
LREAL,SINT,UDINTand other types the classic CPUs do not support. - SCL runs once per scan: no
Sleep,Delayor blocking loops that would trip the cycle watchdog.
The same rules power the free SCL validator, so you can also paste code from other sources and check it.
What you can generate
| Task | Typical blocks |
|---|---|
| Motion and drives | Motor starters, star-delta, reversing, VFD enable and speed setpoints |
| Sequences | CASE-based state machines for batching, filling, cleaning (CIP) and machine cycles |
| Process control | Analog scaling, PID wrappers, alarm limits with hysteresis and deadband |
| Data handling | FIFO and ring buffers, recipe structures, data logging arrays |
| Diagnostics | Alarm handlers, run-hour counters, first-out fault detection |
See finished blocks on the SCL code examples page, or start from one of the templates.
Example: a prompt and the SCL it produces
Prompt: "On-delay start. When Start is TRUE for the configured delay, set Running. Show the remaining time for the HMI." A block of this shape comes back, using a multi-instance TON_TIME:
FUNCTION_BLOCK "FB_DelayedStart"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
Start : Bool; // Request from the operator or sequence
Delay : Time := T#5S; // On-delay before the output switches
END_VAR
VAR_OUTPUT
Running : Bool; // TRUE once the delay has elapsed
Remaining : Time; // Time left until Running switches on
END_VAR
VAR
StartDelay : TON_TIME; // Multi-instance IEC timer, no extra DB
END_VAR
BEGIN
// Call the timer on every scan so it sees the falling edge of Start
#StartDelay(IN := #Start,
PT := #Delay);
#Running := #StartDelay.Q;
IF #Start AND NOT #StartDelay.Q THEN
#Remaining := #Delay - #StartDelay.ET;
ELSE
#Remaining := T#0MS;
END_IF;
END_FUNCTION_BLOCK
S7-1500, S7-1200 and S7-300/400 support
The S7-1500 target uses the full SCL type set, including LREAL and LTIME. The S7-1200 target follows the same syntax with the smaller CPU in mind. The S7-300/400 target sticks to the classic types for TIA Portal and STEP 7 projects. The CPU comparison lists the differences.
What an AI generator does not replace
- Engineering review. Read the code, simulate it (for example with S7-PLCSIM) and test it on the machine before production.
- Safety functions. Emergency stops, guard doors and other safety logic belong in certified F-blocks and a safety-rated design, not in generated standard SCL.
- Your plant standards. Naming, alarm classes and HMI conventions differ between companies. Add them to the description so the generator follows them.
Generate your own SCL block
Describe the logic in plain language and get a Siemens SCL function block you can import into TIA Portal. Free account, no credit card.