自动化设计到HMI
手动创建HMI界面是自动化中最耗时的任务之一。使用T-IA Connect,您可以将数据结构(UDT和DB)转换为图形对象(按钮、仪表、输入字段),这些对象自动定位并链接到您的变量。
前提条件
- 带HMI站(Comfort或Unified)的TIA Portal项目
- 活跃的T-IA Connect服务器
- 为HMI定义的变量表(Tag表)
步骤1:列出并浏览HMI视图
使用API检索现有界面列表并了解HMI项目的层次结构。
curl — GET /api/hmi/screens
curl http://localhost:9000/api/hmi/screens
Response
{
"screens": [
{ "name": "Main_Overview", "width": 1280, "height": 800 },
{ "name": "Motor_Control", "width": 1280, "height": 800 },
{ "name": "Alarms_History", "width": 1280, "height": 800 }
],
"total": 3
}步骤2:创建动态图形对象
发送请求向界面添加对象。您可以指定对象类型、位置、大小,最重要的是其与PLC变量的标签绑定。
curl — POST /api/hmi/screens/Motor_Control/objects
curl -X POST http://localhost:9000/api/hmi/screens/Motor_Control/objects \
-H "Content-Type: application/json" \
-d '{
"type": "Circle",
"name": "Status_Light",
"left": 100,
"top": 150,
"width": 50,
"height": 50,
"bindings": [
{
"property": "BackColor",
"tag": "DB_Motors.Motor_1.Running",
"converter": "BooleanToColor",
"params": { "true": "Green", "false": "Red" }
}
]
}'Response
{
"success": true,
"objectId": "obj_987654",
"name": "Status_Light",
"status": "Created & Linked"
}步骤3:导出并编译HMI
界面生成后,使用API启动HMI站的全局编译,以验证链接一致性。
curl — POST /api/hmi/compile
curl -X POST http://localhost:9000/api/hmi/compile \
-H "Content-Type: application/json" \
-d '{ "stationName": "HMI_TP1200", "rebuildAll": false }'Response
{
"success": true,
"errors": 0,
"warnings": 2,
"compileTimeMs": 14500,
"binaryPath": "C:\\Projects\\Output\\HMI_Data.fw"
}HMI自动化确保DB中的每个变量都有其对应的图形等效项,无任何数据输入错误风险。