大规模自动化 Know-How Protection
Siemens TIA Portal 的 Know-How Protection 通过密码锁定程序块的源代码。程序块在项目树中保持可见(名称、类型、公共接口),但在没有密码的情况下无法读取、导出或修改其内部逻辑。T-IA Connect 允许您通过 REST API、适用于 AI 助手的 MCP 工具或内置的 Copilot 以编程方式应用此保护 - 包括在几秒钟内为整个项目进行批量保护。
先决条件
- 在 T-IA Connect 中打开 TIA Portal 项目(V17、V18、V19 或 V20)
- PLC 程序块编译无误(保护前必须执行)
- T-IA Connect 服务器正在运行(任何版本)
步骤 1:识别未受保护的程序块
列出 PLC 设备中的所有程序块。每个程序块都包含一个 isKnowHowProtected 字段,显示其当前的保护状态。
curl http://localhost:9000/api/devices/PLC_1/blocks \ -H "X-API-Key: your-api-key"
{
"Success": true,
"Data": [
{
"Name": "FB_Fill",
"Type": "FB",
"Number": 1,
"Language": "SCL",
"IsKnowHowProtected": false
},
{
"Name": "FB_Drain",
"Type": "FB",
"Number": 2,
"Language": "SCL",
"IsKnowHowProtected": false
},
{
"Name": "FC_Recipe_Manager",
"Type": "FC",
"Number": 10,
"Language": "SCL",
"IsKnowHowProtected": false
},
{
"Name": "FB_SafetyMonitor",
"Type": "FB",
"Number": 3,
"Language": "LAD",
"IsKnowHowProtected": true
}
]
}步骤 2:编译设备
程序块在受到保护之前必须先进行编译。编译整个设备以确保所有程序块处于有效状态。
curl -X POST http://localhost:9000/api/devices/PLC_1/actions/compile \ -H "X-API-Key: your-api-key"
{
"Success": true,
"Message": "Compilation completed.",
"Data": {
"Errors": 0,
"Warnings": 2
}
}步骤 3:应用 Know-How Protection
通过提供设备名称、程序块名称和密码来保护程序块。密码安全传递,且绝不会被 T-IA Connect 存储。
curl -X POST http://localhost:9000/api/devices/PLC_1/blocks/FB_Fill/actions/protect \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"password": "MySecretPassword123"
}'{
"Success": true,
"Message": "Block 'FB_Fill' is now know-how protected.",
"Data": {
"BlockName": "FB_Fill",
"IsKnowHowProtected": true,
"IsProtectable": true
}
}步骤 4:验证保护状态
通过检查程序块的详细状态来确认保护已正确应用。响应会告知您该程序块是否受保护以及是否可保护。
curl http://localhost:9000/api/devices/PLC_1/blocks/FB_Fill/protection \ -H "X-API-Key: your-api-key"
{
"Success": true,
"Data": {
"BlockName": "FB_Fill",
"IsKnowHowProtected": true,
"IsProtectable": true,
"Reason": null
}
}批量保护
在单个 API 调用中保护数十个程序块。批量端点使用 best-effort 处理,并为每个程序块返回详细报告。
curl -X POST http://localhost:9000/api/devices/PLC_1/blocks/actions/protect-batch \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"blockNames": ["FB_Fill", "FB_Drain", "FC_Recipe_Manager", "DB_Config"],
"password": "MySecretPassword123"
}'{
"Success": true,
"Message": "3/4 blocks protected successfully.",
"Data": {
"TotalRequested": 4,
"Succeeded": 3,
"Failed": 1,
"Details": [
{ "BlockName": "FB_Fill", "IsKnowHowProtected": true, "Reason": null },
{ "BlockName": "FB_Drain", "IsKnowHowProtected": true, "Reason": null },
{ "BlockName": "FC_Recipe_Manager", "IsKnowHowProtected": true, "Reason": null },
{ "BlockName": "DB_Config", "IsKnowHowProtected": true, "Reason": "Already protected." }
]
}
}Know-How Protection 是 Siemens 原生的程序块保护机制。它对 PLC 运行时性能零影响。密码绝不会被 T-IA Connect 存储 - 它作为 SecureString 传递给 Siemens Openness API,且绝不会记录到日志中。
也可通过 MCP 和 Copilot 使用
相同的保护功能可作为适用于 AI 助手(Claude、Gemini、ChatGPT)的 MCP 工具以及内置 Copilot 中使用。工具:protect_block、unprotect_block、get_block_protection_status、protect_blocks(批量)。