Tutorials

Hoe TIA Portal te Automatiseren met Openness API

De definitieve gids om uw Siemens engineering workflow te transformeren in een moderne DevOps pipeline.

T
T-IA Connect Team
15 min lezen
Bijgewerkt op 10 mrt 2026

Waarom Automatisering Onvermijdelijk is

Handmatige engineering in TIA Portal is traag en foutgevoelig. Rechtsklikken, blokken maken, code kopiëren en plakken... Deze repetitieve taken moeten verdwijnen. Dankzij de Openness API (en de T-IA Connect REST wrapper), kunt u TIA Portal besturen zoals elke moderne software.

Vereisten

  • TIA Portal V16, V17, V18, V19 of V21 geïnstalleerd
  • Een T-IA Connect licentie (of Freemium-plan)
  • PowerShell of Python geïnstalleerd op uw machine

Stap 1: Start de REST API

In plaats van TIA Portal handmatig te starten, starten we de T-IA Connect server die als gateway zal fungeren. Open uw terminal en voer uit:

PowerShell
./TiaPortalApi.App.exe --headless

Stap 2: Health Check

Laten we eerst controleren of de API draait en welke TIA Portal versies beschikbaar zijn.

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"]
}

Stap 3: Een Project Aanmaken

Geen 'Bestand > Nieuw' menu's meer. Laten we een POST-verzoek sturen om een leeg project aan te maken.

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
}

Stap 4: PLC Toevoegen & FB Aanmaken

Zoek een CPU in de hardwarecatalogus, voeg deze toe aan het project en maak een Functieblok met SCL-code — alles in een paar API-aanroepen.

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
}

Stap 5: Tags Aanmaken

Importeer PLC-tags (ingangen, uitgangen, geheugen) in bulk via een enkele API-aanroep.

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" }
  ]
}

Stap 6: Project Compileren

Start een compilatie en volg de voortgang via de Jobs API. De compilatie wordt asynchroon uitgevoerd.

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
}

Stap 7: Exporteren naar XML

Exporteer uw blokken naar SimaticML (XML) formaat voor versiebeheer met Git.

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"]
}

Stap 8: Opslaan en Sluiten

Sla het project op en sluit het netjes af. De TIA Portal-instantie is vrij voor de volgende geautomatiseerde run.

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 }

Wat Nu?

U heeft zojuist 90% van de handmatige projectcreatietaken geautomatiseerd. U kunt dit script nu integreren in uw CI/CD pipeline (Jenkins, GitLab CI) om uw code bij elke commit te valideren.

Download de volledige scripts voor deze tutorial en probeer ze met ons Freemium-plan.