Tutorials

So automatisieren Sie TIA Portal mit der Openness-API

Der definitive Leitfaden zur Transformation Ihres Siemens-Engineering-Workflows in eine moderne DevOps-Pipeline.

T
T-IA Connect Team
15 Min. Lesezeit
Aktualisiert am 10. März 2026

Warum Automatisierung unvermeidlich ist

Manuelles Engineering im TIA Portal ist langsam und fehleranfällig. Rechtsklick, Blöcke erstellen, Code kopieren und einfügen... Diese repetitiven Aufgaben müssen verschwinden. Dank der Openness-API (und ihrem T-IA Connect REST-Wrapper) können Sie das TIA Portal wie jede moderne Software steuern.

Voraussetzungen

  • TIA Portal V16, V17, V18, V19 oder V21 installiert
  • Eine T-IA Connect-Lizenz (oder Freemium-Version)
  • PowerShell oder Python auf Ihrem Rechner installiert

Schritt 1: Starten der REST-API

Anstatt das TIA Portal manuell zu starten, starten wir den T-IA Connect-Server, der als Gateway fungiert. Öffnen Sie Ihr Terminal und führen Sie aus:

PowerShell
./TiaPortalApi.App.exe --headless

Schritt 2: Health Check

Bevor wir beginnen, überprüfen wir, ob die API läuft und welche TIA Portal-Versionen auf dem Rechner verfügbar sind.

curl
curl http://localhost:9000/api/health

curl http://localhost:9000/api/health/versions
Response
{
  "status": "healthy",
  "tiaPortalConnected": true,
  "uptime": "00:01:23"
}

{
  "installedVersions": ["V17", "V18", "V19"]
}

Schritt 3: Projekt erstellen

Keine 'Datei > Neu'-Menüs mehr. Senden wir eine POST-Anfrage, um ein leeres Projekt zu instanziieren.

curl — POST /api/projects/actions/create
curl -X POST http://localhost:9000/api/projects/actions/create \
  -H "Content-Type: application/json" \
  -d '{
    "name": "MyAutomatedProject",
    "path": "C:\\TIA_Projects",
    "version": "V19"
  }'
Response
{
  "name": "MyAutomatedProject",
  "path": "C:\\TIA_Projects\\MyAutomatedProject",
  "version": "V19",
  "created": true
}

Schritt 4: PLC hinzufügen & FB erstellen

Durchsuchen Sie den Hardwarekatalog nach einer CPU, fügen Sie sie dem Projekt hinzu und erstellen Sie dann einen Funktionsbaustein mit SCL-Code — alles in wenigen API-Aufrufen.

curl — Search catalog + Add device
# Search the hardware catalog
curl -X POST http://localhost:9000/api/catalog/actions/search \
  -H "Content-Type: application/json" \
  -d '{ "searchPattern": "CPU 1511" }'

# Add the device to the project
curl -X POST http://localhost:9000/api/projects/devices/actions/add \
  -H "Content-Type: application/json" \
  -d '{
    "name": "PLC_1",
    "typeId": "<typeId from search>",
    "deviceName": "CPU 1511C-1 PN"
  }'

# Create a Function Block
curl -X POST http://localhost:9000/api/devices/PLC_1/blocks \
  -H "Content-Type: application/json" \
  -d '{
    "name": "FB_MotorControl",
    "type": "FB",
    "programmingLanguage": "SCL"
  }'

# Add SCL code to the block
curl -X POST http://localhost:9000/api/devices/PLC_1/blocks/FB_MotorControl/networks \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Motor control logic",
    "code": "#Running := #Start AND NOT #Stop;\nIF #Running THEN\n  #Speed := #SpeedSetpoint;\nEND_IF;"
  }'
Response
// Block creation response
{
  "name": "FB_MotorControl",
  "type": "FB",
  "programmingLanguage": "SCL",
  "number": 1
}

// Network added
{
  "networkId": 1,
  "title": "Motor control logic",
  "created": true
}

Schritt 5: Tags erstellen

Importieren Sie PLC-Tags (Eingänge, Ausgänge, Speicher) per Massenimport über einen einzigen API-Aufruf. Kein einzelnes Durchklicken der Tag-Tabellen mehr.

curl — POST /api/devices/PLC_1/tags/actions/import
curl -X POST http://localhost:9000/api/devices/PLC_1/tags/actions/import \
  -H "Content-Type: application/json" \
  -d '{
    "tagTable": "Motors",
    "tags": [
      { "name": "Motor1_Start",   "dataType": "Bool", "address": "%I0.0" },
      { "name": "Motor1_Stop",    "dataType": "Bool", "address": "%I0.1" },
      { "name": "Motor1_Running", "dataType": "Bool", "address": "%Q0.0" },
      { "name": "Motor1_Speed",   "dataType": "Real", "address": "%QD4"  },
      { "name": "Motor1_Fault",   "dataType": "Bool", "address": "%Q0.1" }
    ]
  }'
Response
{
  "tagTable": "Motors",
  "importedCount": 5,
  "tags": [
    { "name": "Motor1_Start",   "dataType": "Bool", "address": "%I0.0" },
    { "name": "Motor1_Stop",    "dataType": "Bool", "address": "%I0.1" },
    { "name": "Motor1_Running", "dataType": "Bool", "address": "%Q0.0" },
    { "name": "Motor1_Speed",   "dataType": "Real", "address": "%QD4"  },
    { "name": "Motor1_Fault",   "dataType": "Bool", "address": "%Q0.1" }
  ]
}

Schritt 6: Projekt kompilieren

Lösen Sie eine Kompilierung aus und verfolgen Sie den Fortschritt über die Jobs-API. Die Kompilierung läuft asynchron — fragen Sie den Job-Status ab, bis er abgeschlossen ist.

curl — Compile + Poll job
# Start compilation
curl -X POST http://localhost:9000/api/devices/PLC_1/actions/compile

# Poll the job status (replace <jobId>)
curl http://localhost:9000/api/jobs/<jobId>
Response
// Compilation started
{ "jobId": "c7f3a1b2-...", "status": "running" }

// Job completed
{
  "jobId": "c7f3a1b2-...",
  "status": "completed",
  "errors": [],
  "warnings": 2
}

Schritt 7: Nach XML exportieren

Exportieren Sie Ihre Bausteine im SimaticML-Format (XML) zur Versionskontrolle mit Git. Dies ist der Schlüssel, um SPS-Code wie jeden anderen Quellcode zu behandeln.

curl — POST /api/devices/PLC_1/blocks/actions/export
curl -X POST http://localhost:9000/api/devices/PLC_1/blocks/actions/export \
  -H "Content-Type: application/json" \
  -d '{
    "blocks": ["FB_MotorControl"],
    "exportPath": "C:\\TIA_Projects\\Export"
  }'
Response
{
  "exportedCount": 1,
  "exportPath": "C:\\TIA_Projects\\Export",
  "files": ["FB_MotorControl.xml"]
}

Schritt 8: Speichern und Schließen

Speichern Sie das Projekt und schließen Sie es ordnungsgemäß. Die TIA Portal-Instanz wird freigegeben und ist bereit für den nächsten automatisierten Lauf.

curl — Save & Close
curl -X POST http://localhost:9000/api/projects/actions/save

curl -X POST http://localhost:9000/api/projects/actions/close
Response
{ "saved": true }

{ "closed": true }

Was kommt als Nächstes?

Sie haben gerade 90 % der manuellen Projekterstellungsaufgaben automatisiert. Sie können dieses Skript nun in Ihre CI/CD-Pipeline (Jenkins, GitLab CI) integrieren, um Ihren Code bei jedem Commit zu validieren.

Laden Sie die vollständigen Skripte für dieses Tutorial herunter und probieren Sie sie mit unserer kostenlosen Freemium-Version aus.