|
|
@@ -22,8 +22,10 @@ from .mcp_app import mcp
|
|
|
"通过采集网关对 Siemens S7 TCP 设备执行原始字节读取。调用 "
|
|
|
"{base_url}/api/dc-gateway/s7/read。请求字段使用网关/汇采一致命名:"
|
|
|
"ip 为 PLC 地址,port 默认 102,rock 为机架号,slot 为槽号,"
|
|
|
- "tsap_conn_type 默认 PG,可选 PG、OP、BASIC。read 必须包含 area、start、size;"
|
|
|
- "area 可用 DB、M、I、Q;area=DB 时 read.db 必须大于 0。"
|
|
|
+ "device_type 为设备类型,默认 S7-1200,可传 S7-1200、S7-Smart200。"
|
|
|
+ "tsap_conn_type 可选 PG、OP、BASIC;未传时 S7-1200 使用 PG,"
|
|
|
+ "device_type=S7-Smart200 时使用 OP。read 必须包含 area、start、size;"
|
|
|
+ "area 可用 DB、M、I、Q,S7-Smart200 还支持 V;area=DB 时 read.db 必须大于 0。"
|
|
|
"该接口不解析业务值,只返回语义化 communication:S7_CONNECT、S7_CONNECTED、"
|
|
|
"S7_READ、原始十六进制字节、S7_DISCONNECT 或 S7_ERROR。"
|
|
|
"响应透传上游 JSON,code=0 表示业务成功,code!=0 时 msg 为失败原因。"
|
|
|
@@ -35,9 +37,9 @@ def s7_raw_read(
|
|
|
read: dict[str, Any],
|
|
|
rock: int = 0,
|
|
|
slot: int = 1,
|
|
|
- device_type: str = "S7TCP",
|
|
|
+ device_type: str = "S7-1200",
|
|
|
port: int = 102,
|
|
|
- tsap_conn_type: str = "PG",
|
|
|
+ tsap_conn_type: str | None = None,
|
|
|
) -> dict[str, Any]:
|
|
|
return api_s7_raw_read(
|
|
|
project_key,
|
|
|
@@ -57,8 +59,11 @@ def s7_raw_read(
|
|
|
"通过采集网关读取 Siemens S7 TCP 点位并转换为业务值。调用 "
|
|
|
"{base_url}/api/dc-gateway/s7/read_points。请求字段使用网关/汇采一致命名:"
|
|
|
"ip 为 PLC 地址,port 默认 102,rock 为机架号,slot 为槽号,"
|
|
|
- "tsap_conn_type 默认 PG,可选 PG、OP、BASIC。points 为点位数组,每个点位必须包含 "
|
|
|
- "area、start、type;area 可用 DB、M、I、Q;area=DB 时 db 必须大于 0。"
|
|
|
+ "device_type 为设备类型,默认 S7-1200,可传 S7-1200、S7-Smart200。"
|
|
|
+ "tsap_conn_type 可选 PG、OP、BASIC;未传时 S7-1200 使用 PG,"
|
|
|
+ "device_type=S7-Smart200 时使用 OP。points 为点位数组,每个点位必须包含 "
|
|
|
+ "area、start、type;area 可用 DB、M、I、Q,S7-Smart200 还支持 V;"
|
|
|
+ "area=DB 时 db 必须大于 0。"
|
|
|
"type 可用 bool、byte、int8、int16、uint16、int32、uint32、int64、uint64、"
|
|
|
"float32、float64;bool 点可传 bit 读取指定 0..7 位,非 bool 点不能传 bit。"
|
|
|
"S7 多字节数值按大端解析,响应 data.points[].value 为转换后的业务值,"
|
|
|
@@ -71,9 +76,9 @@ def s7_point_collect_test(
|
|
|
rock: int,
|
|
|
slot: int,
|
|
|
points: list[dict[str, Any]],
|
|
|
- device_type: str = "S7TCP",
|
|
|
+ device_type: str = "S7-1200",
|
|
|
port: int = 102,
|
|
|
- tsap_conn_type: str = "PG",
|
|
|
+ tsap_conn_type: str | None = None,
|
|
|
) -> dict[str, Any]:
|
|
|
return api_s7_point_collect_test(
|
|
|
project_key,
|
|
|
@@ -101,16 +106,26 @@ def s7_connect_scan(project_key: str, ip: str) -> dict[str, Any]:
|
|
|
return api_s7_connect_scan(project_key, ip=ip)
|
|
|
|
|
|
|
|
|
+def _resolve_collector_s7_tsap_conn_type(device_type: int, tsap_conn_type: str | None) -> str:
|
|
|
+ normalized_tsap = str(tsap_conn_type or "").strip().upper()
|
|
|
+ if normalized_tsap:
|
|
|
+ return normalized_tsap
|
|
|
+ if int(device_type) == 3:
|
|
|
+ return "OP"
|
|
|
+ return "PG"
|
|
|
+
|
|
|
+
|
|
|
@mcp.tool(
|
|
|
name="collector.s7_device_create",
|
|
|
description=(
|
|
|
"汇采-创建 S7 设备。调用 {data_collector_base_url}/api/collector/device,"
|
|
|
"与 Modbus 创建设备共用地址,但请求体固定 type=s7,入参使用 S7 字段。"
|
|
|
"创建设备必须传 name 名称、ip IP 地址、rock 机架号(轨道号)、slot 槽号;"
|
|
|
- "port 默认 102,device_type 默认 1,tsap_conn_type 默认 PG。"
|
|
|
+ "port 默认 102,device_type 默认 1。tsap_conn_type 可选 PG、OP、BASIC;"
|
|
|
+ "未传时 device_type=1 使用 PG,device_type=3 时使用 OP。"
|
|
|
"默认参数: is_persistent=false, "
|
|
|
"device_group_id=0, timeout=3, alarm_interval=90, collect_interval=5。"
|
|
|
- "device_type: 1=S7-1200, 2=S7-1500, 3=S7 Smart 200。"
|
|
|
+ "device_type: 1=S7-1200, 2=S7-1500, 3=S7-Smart200。"
|
|
|
"tsap_conn_type 可用 PG、OP、BASIC。响应透传上游 JSON,state=0 表示业务成功。"
|
|
|
),
|
|
|
)
|
|
|
@@ -122,7 +137,7 @@ def collector_s7_device_create(
|
|
|
slot: int,
|
|
|
port: int = 102,
|
|
|
device_type: int = 1,
|
|
|
- tsap_conn_type: str = "PG",
|
|
|
+ tsap_conn_type: str | None = None,
|
|
|
is_persistent: bool = False,
|
|
|
device_group_id: int = 0,
|
|
|
timeout: int = 3,
|
|
|
@@ -138,7 +153,7 @@ def collector_s7_device_create(
|
|
|
"slot": slot,
|
|
|
"port": port,
|
|
|
"device_type": device_type,
|
|
|
- "tsap_conn_type": tsap_conn_type,
|
|
|
+ "tsap_conn_type": _resolve_collector_s7_tsap_conn_type(device_type, tsap_conn_type),
|
|
|
"is_persistent": is_persistent,
|
|
|
"device_group_id": device_group_id,
|
|
|
"timeout": timeout,
|
|
|
@@ -153,10 +168,11 @@ def collector_s7_device_create(
|
|
|
description=(
|
|
|
"汇采-编辑 S7 设备。调用 {data_collector_base_url}/api/collector/s7/device/update。"
|
|
|
"必须传 ori_id 原设备 id、name、ip、rock、slot;port 默认 102,device_type 默认 1,"
|
|
|
- "tsap_conn_type 默认 PG。编辑前设备不能处于已连接状态;若已连接,请先调用 "
|
|
|
+ "tsap_conn_type 可选 PG、OP、BASIC;未传时 device_type=1 使用 PG,device_type=3 时使用 OP。"
|
|
|
+ "编辑前设备不能处于已连接状态;若已连接,请先调用 "
|
|
|
"collector.device_disconnect,并传 device_type=s7。该接口是全量更新语义。"
|
|
|
"默认参数: is_persistent=false, device_group_id=0, timeout=3, alarm_interval=90, "
|
|
|
- "collect_interval=5。device_type: 1=S7-1200, 2=S7-1500, 3=S7 Smart 200。"
|
|
|
+ "collect_interval=5。device_type: 1=S7-1200, 2=S7-1500, 3=S7-Smart200。"
|
|
|
"tsap_conn_type 可用 PG、OP、BASIC。响应透传上游 JSON,state=0 表示业务成功。"
|
|
|
),
|
|
|
)
|
|
|
@@ -169,7 +185,7 @@ def collector_s7_device_edit(
|
|
|
slot: int,
|
|
|
port: int = 102,
|
|
|
device_type: int = 1,
|
|
|
- tsap_conn_type: str = "PG",
|
|
|
+ tsap_conn_type: str | None = None,
|
|
|
is_persistent: bool = False,
|
|
|
device_group_id: int = 0,
|
|
|
timeout: int = 3,
|
|
|
@@ -186,7 +202,7 @@ def collector_s7_device_edit(
|
|
|
"slot": slot,
|
|
|
"port": port,
|
|
|
"device_type": device_type,
|
|
|
- "tsap_conn_type": tsap_conn_type,
|
|
|
+ "tsap_conn_type": _resolve_collector_s7_tsap_conn_type(device_type, tsap_conn_type),
|
|
|
"is_persistent": is_persistent,
|
|
|
"device_group_id": device_group_id,
|
|
|
"timeout": timeout,
|