IndustryKit Siemens S7
S7 source 使用经典 ISO-on-TCP 主动读取 PLC 的 DB、Input、Output 和 Marker 区域。
配置层级
| 层级 |
作用 |
[[sources]] |
定义一个 S7 采集任务;可重复配置多台 PLC。 |
[sources.s7] |
配置当前 source 的 PLC 连接、rack/slot 和超时。 |
[[sources.s7.points]] |
定义一个读取点位;每增加一项就多采集一个输出字段。 |
每个 [[sources]] 只能包含一个协议子表;type = "s7" 必须与 [sources.s7] 对应。
field 是写入 measurement 的输出字段名,area、db_number 和 offset 才是 PLC 中的
读取位置。
配置
[[sources]]
id = "s7-plc"
type = "s7"
measurement = "s7_metrics"
interval = "10s"
tags = { device = "s7-1200" }
[sources.s7]
address = "192.0.2.40:102"
rack = 0
slot = 1
timeout = "3s"
[[sources.s7.points]]
field = "motor_speed"
area = "db"
db_number = 10
byte_offset = 0
data_type = "uint16"
scale = 0.1
[[sources.s7.points]]
field = "pump_running"
area = "db"
db_number = 10
byte_offset = 2
bit_offset = 0
data_type = "bool"
[[sources.s7.points]]
field = "batch_name"
area = "db"
db_number = 10
byte_offset = 8
data_type = "s7_string"
length = 20
参数
[[sources]]
| 字段 |
默认值 |
说明 |
id |
无 |
必填且在配置中唯一;同时作为 source_id 标签。 |
type |
无 |
必须设置为 s7。 |
measurement |
industrial |
上报的指标集或日志来源名称。 |
interval |
10s |
轮询周期,必须大于 0。 |
tags |
{} |
当前 source 的静态标签。 |
[sources.s7]
| 字段 |
默认值 |
说明 |
address |
无 |
必填的 PLC host:port;经典 S7 通常使用端口 102。 |
rack |
0 |
CPU rack,范围为 0..7。 |
slot |
1 |
CPU slot,范围为 1..31。 |
timeout |
3s |
单次连接或读取超时,必须大于 0。 |
[[sources.s7.points]]
| 字段 |
默认值 |
说明 |
field |
无 |
必填的输出字段名。 |
category |
metric |
输出类型:metric 或 logging。 |
tags |
{} |
当前点位的静态标签。 |
area |
无 |
必填:db、input、output 或 marker。 |
db_number |
0 |
area = "db" 时必须大于 0;其他区域必须不设置或为 0。 |
byte_offset |
0 |
区域内的零基字节偏移。 |
bit_offset |
0 |
仅 bool 使用,范围为 0..7;其他类型必须为 0。 |
data_type |
无 |
必填:bool、int8、uint8、int16、uint16、int32、uint32、int64、uint64、float32、float64、string、s7_string 或 bytes。 |
length |
0 |
string/bytes 必须为 1..4096;s7_string 必须为 1..254;其他类型不设置。 |
scale |
1 |
数值变换乘数。 |
offset |
0 |
数值变换偏移;最终值为 value * scale + offset。 |
on_change |
false |
metric 是否仅在值变化时发送;logging 始终按变化发送。 |
emit_initial |
false |
对 logging 或启用 on_change 的 metric,是否发送首次观察值。 |
status |
info |
仅用于 logging 的状态字段。 |
数据与限制
- 相邻或重叠地址会按 area/DB 合并读取,单个合并范围最大 4096 bytes。
- 整数和浮点按 S7 常用 big-endian 解码。
- 单个 source 至少配置一个 point;点位读取范围不能超过 S7 地址空间。
- 相同
field 与最终标签组合不能重复。
- S7-1200/1500 必须开启 PUT/GET,并使用非 optimized DB access。
- 当前不支持符号变量、自动发现和 PLC 写入。