Tutoriels

Comment Automatiser TIA Portal avec l'API Openness

Le guide définitif pour transformer votre workflow d'ingénierie Siemens en pipeline DevOps moderne.

T
Équipe T-IA Connect
15 min de lecture
Mis à jour le 10 Mars 2026

Pourquoi l'automatisation est inévitable

L'ingénierie manuelle sur TIA Portal est lente et sujette aux erreurs. Clic-droit, créer un bloc, copier-coller du code... Ces tâches répétitives doivent disparaître. Grâce à l'API Openness (et son wrapper REST T-IA Connect), vous pouvez piloter TIA Portal comme n'importe quel logiciel moderne.

Prérequis

  • TIA Portal V16, V17, V18, V19 ou V21 installé
  • Une licence T-IA Connect (ou version Freemium)
  • PowerShell ou Python installé sur votre machine

Étape 1 : Démarrer l'API REST

Au lieu de lancer TIA Portal manuellement, nous allons lancer le serveur T-IA Connect qui va agir comme une passerelle. Ouvrez votre terminal et lancez :

PowerShell
./TiaPortalApi.App.exe --headless

Étape 2 : Health Check

Avant toute chose, vérifions que l'API fonctionne et quelles versions de TIA Portal sont disponibles sur la machine.

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

Étape 3 : Créer un Projet

Fini les menus 'Fichier > Nouveau'. Envoyons une requête POST pour instancier un projet vierge.

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
}

Étape 4 : Ajouter un PLC & Créer un FB

Recherchez un CPU dans le catalogue matériel, ajoutez-le au projet, puis créez un Function Block avec du code SCL — le tout en quelques appels API.

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
}

Étape 5 : Créer des Tags

Importez des tags PLC (entrées, sorties, mémoire) en masse via un seul appel API. Plus besoin de cliquer dans les tables de tags une par une.

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

Étape 6 : Compiler le Projet

Déclenchez une compilation et suivez sa progression via l'API Jobs. La compilation s'exécute de manière asynchrone — interrogez le statut du job jusqu'à la fin.

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
}

Étape 7 : Exporter en XML

Exportez vos blocs au format SimaticML (XML) pour le contrôle de version avec Git. C'est la clé pour traiter le code PLC comme n'importe quel autre code source.

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

Étape 8 : Sauvegarder et Fermer

Sauvegardez le projet et fermez-le proprement. L'instance TIA Portal est libérée et prête pour le prochain run automatisé.

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 }

Et maintenant ?

Vous venez d'automatiser 90% des tâches manuelles de création de projet. Vous pouvez maintenant intégrer ce script dans votre pipeline CI/CD (Jenkins, GitLab CI) pour valider votre code à chaque commit.

Téléchargez les scripts complets de ce tutoriel et essayez-les avec notre version Freemium gratuite.