修改ModbusTCP 端口映射功能 & 更新README端口说明

This commit is contained in:
yiyi 2025-12-30 00:05:31 +08:00
parent e6199c1bf2
commit 12a1a0e738
9 changed files with 75 additions and 70 deletions

View File

@ -176,26 +176,26 @@ After=network.target
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/bin/bash -c 'iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020' ExecStart=/bin/bash -c 'iptables-legacy -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020'
RemainAfterExit=yes RemainAfterExit=yes
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
PORTEOF PORTEOF
systemctl daemon-reload
systemctl enable vr-port-mapping.service systemctl enable vr-port-mapping.service
systemctl start vr-port-mapping.service systemctl start vr-port-mapping.service
else else
echo "端口映射服务已存在,跳过创建..." echo "端口映射服务已存在,跳过创建..."
# 确保服务处于启用状态
systemctl enable vr-port-mapping.service 2>/dev/null || true systemctl enable vr-port-mapping.service 2>/dev/null || true
systemctl start vr-port-mapping.service 2>/dev/null || true systemctl start vr-port-mapping.service 2>/dev/null || true
fi fi
# 检查iptables规则是否已存在 # 检查iptables规则是否已存在
if ! iptables -t nat -C PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then if ! iptables-legacy -t nat -C PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then
echo "添加iptables端口映射规则..." echo "添加iptables端口映射规则..."
iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 iptables-legacy -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020
else else
echo "iptables规则已存在跳过添加..." echo "iptables规则已存在跳过添加..."
fi fi
@ -310,7 +310,7 @@ if [ "${REMAINING_APPS}" -eq 0 ]; then
rm -f /etc/systemd/system/vr-port-mapping.service rm -f /etc/systemd/system/vr-port-mapping.service
# 清理iptables规则 # 清理iptables规则
iptables -t nat -D PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true iptables-legacy -t nat -D PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true
# 清理注册目录 # 清理注册目录
rm -rf "${REGISTRY_DIR}" rm -rf "${REGISTRY_DIR}"

View File

@ -177,7 +177,7 @@ After=network.target
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/bin/bash -c 'iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020' ExecStart=/bin/bash -c 'iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020'
RemainAfterExit=yes RemainAfterExit=yes
[Install] [Install]
@ -193,12 +193,12 @@ else
systemctl start vr-port-mapping.service 2>/dev/null || true systemctl start vr-port-mapping.service 2>/dev/null || true
fi fi
# 检查iptables规则是否已存在 # 检查iptables-legacy规则是否已存在
if ! iptables -t nat -C PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then if ! iptables-legacy -t nat -C PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then
echo "添加iptables端口映射规则..." echo "添加iptables-legacy端口映射规则..."
iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020
else else
echo "iptables规则已存在,跳过添加..." echo "iptables-legacy规则已存在,跳过添加..."
fi fi
# 检查并创建当前用户的桌面快捷方式 # 检查并创建当前用户的桌面快捷方式
@ -310,8 +310,8 @@ if [ "${REMAINING_APPS}" -eq 0 ]; then
systemctl disable vr-port-mapping.service 2>/dev/null || true systemctl disable vr-port-mapping.service 2>/dev/null || true
rm -f /etc/systemd/system/vr-port-mapping.service rm -f /etc/systemd/system/vr-port-mapping.service
# 清理iptables规则 # 清理iptables-legacy规则
iptables -t nat -D PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true iptables-legacy -t nat -D PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true
# 清理注册目录 # 清理注册目录
rm -rf "${REGISTRY_DIR}" rm -rf "${REGISTRY_DIR}"

View File

@ -176,7 +176,7 @@ After=network.target
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/bin/bash -c 'iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020' ExecStart=/bin/bash -c 'iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020'
RemainAfterExit=yes RemainAfterExit=yes
[Install] [Install]
@ -192,12 +192,12 @@ else
systemctl start vr-port-mapping.service 2>/dev/null || true systemctl start vr-port-mapping.service 2>/dev/null || true
fi fi
# 检查iptables规则是否已存在 # 检查iptables-legacy规则是否已存在
if ! iptables -t nat -C PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then if ! iptables-legacy -t nat -C PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then
echo "添加iptables端口映射规则..." echo "添加iptables-legacy端口映射规则..."
iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020
else else
echo "iptables规则已存在,跳过添加..." echo "iptables-legacy规则已存在,跳过添加..."
fi fi
# 检查并创建当前用户的桌面快捷方式 # 检查并创建当前用户的桌面快捷方式
@ -309,8 +309,8 @@ if [ "${REMAINING_APPS}" -eq 0 ]; then
systemctl disable vr-port-mapping.service 2>/dev/null || true systemctl disable vr-port-mapping.service 2>/dev/null || true
rm -f /etc/systemd/system/vr-port-mapping.service rm -f /etc/systemd/system/vr-port-mapping.service
# 清理iptables规则 # 清理iptables-legacy规则
iptables -t nat -D PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true iptables-legacy -t nat -D PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true
# 清理注册目录 # 清理注册目录
rm -rf "${REGISTRY_DIR}" rm -rf "${REGISTRY_DIR}"

View File

@ -187,7 +187,7 @@ After=network.target
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/bin/bash -c 'iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020' ExecStart=/bin/bash -c 'iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020'
RemainAfterExit=yes RemainAfterExit=yes
[Install] [Install]
@ -203,12 +203,12 @@ else
systemctl start vr-port-mapping.service 2>/dev/null || true systemctl start vr-port-mapping.service 2>/dev/null || true
fi fi
# 检查iptables规则是否已存在 # 检查iptables-legacy规则是否已存在
if ! iptables -t nat -C PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then if ! iptables-legacy -t nat -C PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then
echo "添加iptables端口映射规则..." echo "添加iptables-legacy端口映射规则..."
iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020
else else
echo "iptables规则已存在,跳过添加..." echo "iptables-legacy规则已存在,跳过添加..."
fi fi
# 检查并创建当前用户的桌面快捷方式 # 检查并创建当前用户的桌面快捷方式
@ -320,8 +320,8 @@ if [ "${REMAINING_APPS}" -eq 0 ]; then
systemctl disable vr-port-mapping.service 2>/dev/null || true systemctl disable vr-port-mapping.service 2>/dev/null || true
rm -f /etc/systemd/system/vr-port-mapping.service rm -f /etc/systemd/system/vr-port-mapping.service
# 清理iptables规则 # 清理iptables-legacy规则
iptables -t nat -D PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true iptables-legacy -t nat -D PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true
# 清理注册目录 # 清理注册目录
rm -rf "${REGISTRY_DIR}" rm -rf "${REGISTRY_DIR}"

View File

@ -180,26 +180,26 @@ After=network.target
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/bin/bash -c 'iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020' ExecStart=/bin/bash -c 'iptables-legacy -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020'
RemainAfterExit=yes RemainAfterExit=yes
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
PORTEOF PORTEOF
systemctl daemon-reload
systemctl enable vr-port-mapping.service systemctl enable vr-port-mapping.service
systemctl start vr-port-mapping.service systemctl start vr-port-mapping.service
else else
echo "端口映射服务已存在,跳过创建..." echo "端口映射服务已存在,跳过创建..."
# 确保服务处于启用状态
systemctl enable vr-port-mapping.service 2>/dev/null || true systemctl enable vr-port-mapping.service 2>/dev/null || true
systemctl start vr-port-mapping.service 2>/dev/null || true systemctl start vr-port-mapping.service 2>/dev/null || true
fi fi
# 检查iptables规则是否已存在 # 检查iptables规则是否已存在
if ! iptables -t nat -C PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then if ! iptables-legacy -t nat -C PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then
echo "添加iptables端口映射规则..." echo "添加iptables端口映射规则..."
iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 iptables-legacy -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020
else else
echo "iptables规则已存在跳过添加..." echo "iptables规则已存在跳过添加..."
fi fi
@ -314,7 +314,7 @@ if [ "${REMAINING_APPS}" -eq 0 ]; then
rm -f /etc/systemd/system/vr-port-mapping.service rm -f /etc/systemd/system/vr-port-mapping.service
# 清理iptables规则 # 清理iptables规则
iptables -t nat -D PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true iptables-legacy -t nat -D PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true
# 清理注册目录 # 清理注册目录
rm -rf "${REGISTRY_DIR}" rm -rf "${REGISTRY_DIR}"

View File

@ -176,7 +176,7 @@ After=network.target
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/bin/bash -c 'iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020' ExecStart=/bin/bash -c 'iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020'
RemainAfterExit=yes RemainAfterExit=yes
[Install] [Install]
@ -192,12 +192,12 @@ else
systemctl start vr-port-mapping.service 2>/dev/null || true systemctl start vr-port-mapping.service 2>/dev/null || true
fi fi
# 检查iptables规则是否已存在 # 检查iptables-legacy规则是否已存在
if ! iptables -t nat -C PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then if ! iptables-legacy -t nat -C PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then
echo "添加iptables端口映射规则..." echo "添加iptables-legacy端口映射规则..."
iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020
else else
echo "iptables规则已存在,跳过添加..." echo "iptables-legacy规则已存在,跳过添加..."
fi fi
# 检查并创建当前用户的桌面快捷方式 # 检查并创建当前用户的桌面快捷方式
@ -309,8 +309,8 @@ if [ "${REMAINING_APPS}" -eq 0 ]; then
systemctl disable vr-port-mapping.service 2>/dev/null || true systemctl disable vr-port-mapping.service 2>/dev/null || true
rm -f /etc/systemd/system/vr-port-mapping.service rm -f /etc/systemd/system/vr-port-mapping.service
# 清理iptables规则 # 清理iptables-legacy规则
iptables -t nat -D PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true iptables-legacy -t nat -D PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true
# 清理注册目录 # 清理注册目录
rm -rf "${REGISTRY_DIR}" rm -rf "${REGISTRY_DIR}"

View File

@ -181,7 +181,7 @@ After=network.target
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/bin/bash -c 'iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020' ExecStart=/bin/bash -c 'iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020'
RemainAfterExit=yes RemainAfterExit=yes
[Install] [Install]
@ -197,12 +197,12 @@ else
systemctl start vr-port-mapping.service 2>/dev/null || true systemctl start vr-port-mapping.service 2>/dev/null || true
fi fi
# 检查iptables规则是否已存在 # 检查iptables-legacy规则是否已存在
if ! iptables -t nat -C PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then if ! iptables-legacy -t nat -C PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then
echo "添加iptables端口映射规则..." echo "添加iptables-legacy端口映射规则..."
iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020
else else
echo "iptables规则已存在,跳过添加..." echo "iptables-legacy规则已存在,跳过添加..."
fi fi
# 检查并创建当前用户的桌面快捷方式 # 检查并创建当前用户的桌面快捷方式
@ -314,8 +314,8 @@ if [ "${REMAINING_APPS}" -eq 0 ]; then
systemctl disable vr-port-mapping.service 2>/dev/null || true systemctl disable vr-port-mapping.service 2>/dev/null || true
rm -f /etc/systemd/system/vr-port-mapping.service rm -f /etc/systemd/system/vr-port-mapping.service
# 清理iptables规则 # 清理iptables-legacy规则
iptables -t nat -D PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true iptables-legacy -t nat -D PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true
# 清理注册目录 # 清理注册目录
rm -rf "${REGISTRY_DIR}" rm -rf "${REGISTRY_DIR}"

View File

@ -178,7 +178,7 @@ After=network.target
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/bin/bash -c 'iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020' ExecStart=/bin/bash -c 'iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020'
RemainAfterExit=yes RemainAfterExit=yes
[Install] [Install]
@ -194,12 +194,12 @@ else
systemctl start vr-port-mapping.service 2>/dev/null || true systemctl start vr-port-mapping.service 2>/dev/null || true
fi fi
# 检查iptables规则是否已存在 # 检查iptables-legacy规则是否已存在
if ! iptables -t nat -C PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then if ! iptables-legacy -t nat -C PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null; then
echo "添加iptables端口映射规则..." echo "添加iptables-legacy端口映射规则..."
iptables -t nat -A PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 iptables-legacy -t nat -A PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020
else else
echo "iptables规则已存在,跳过添加..." echo "iptables-legacy规则已存在,跳过添加..."
fi fi
# 检查并创建当前用户的桌面快捷方式 # 检查并创建当前用户的桌面快捷方式
@ -311,8 +311,8 @@ if [ "${REMAINING_APPS}" -eq 0 ]; then
systemctl disable vr-port-mapping.service 2>/dev/null || true systemctl disable vr-port-mapping.service 2>/dev/null || true
rm -f /etc/systemd/system/vr-port-mapping.service rm -f /etc/systemd/system/vr-port-mapping.service
# 清理iptables规则 # 清理iptables-legacy规则
iptables -t nat -D PREROUTING -p tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true iptables-legacy -t nat -D PREROUTING -p tcp -m tcp --dport 502 -j REDIRECT --to-port 5020 2>/dev/null || true
# 清理注册目录 # 清理注册目录
rm -rf "${REGISTRY_DIR}" rm -rf "${REGISTRY_DIR}"

View File

@ -73,18 +73,23 @@ GrabBag/
## 应用程序说明 ## 应用程序说明
| 应用名称 | 功能描述 | 位置 | 备注 | | 应用名称 | 功能描述 | 使用设备 | TCP | Modbus TCP | Modbus RTU | 备注 |
|---------|---------|------|------| |---------|---------|---------|-----|------------|------------|------|
| GrabBagApp | 编织袋视觉定位与拆垛 | `App/GrabBag/` | 支持 1-2 个相机TCP 服务端与机器人通信 | | GrabBagApp | 编织袋视觉定位与拆垛 | VzNL 3D相机 | 6800 | 502→5020 | - | 支持 1-2 个相机 |
| BeltTearingApp | 实时检测传送带撕裂情况 | `App/BeltTearing/` | 客户端-服务端分离App + Server | | BeltTearingApp | 实时检测传送带撕裂情况 | VzNL 3D相机 | 5800客户协议<br>5900上下位机 | 502→5020 | 温度读取 | 客户端-服务端分离 |
| LapWeldApp | 焊缝质量检测 | `App/LapWeld/` | - | | LapWeldApp | 焊缝质量检测 | VzNL 3D相机 | 5020 | - | - | - |
| WorkpieceApp | 工件角点检测与定位 | `App/Workpiece/` | - | | WorkpieceApp | 工件角点检测与定位 | VzNL 3D相机 | 7800 | 502→5020 | - | - |
| WorkpiecePositionApp | 双传感器工件抓取定位 | `App/WorkpieceProject/` | WorkpieceProject 子应用 | | WorkpiecePositionApp | 双传感器工件抓取定位 | EpicEye + VzNL 3D相机 | 客户端连接5901 | 502→5020 | - | 连接 BinocularMarkApp |
| WorkpieceSpliceApp | 闭环控制工件拼接组装 | `App/WorkpieceProject/` | WorkpieceProject 子应用 | | WorkpieceSpliceApp | 闭环控制工件拼接组装 | VzNL 3D相机 | 客户端连接5901 | 502→5020 | - | 连接 BinocularMarkApp |
| BinocularMarkApp | 3D Mark 点检测服务 | `App/BinocularMark/` | - | | BinocularMarkApp | 3D Mark 点检测服务 | 大恒相机(双目) | 5901 | - | - | 无 Modbus |
| ParticleSizeApp | 颗粒粒度分析 | `App/ParticleSize/` | - | | ParticleSizeApp | 颗粒粒度分析 | VzNL 3D相机 | 7900 | 502→5020 | - | - |
| TunnelChannelApp | 隧道通道检测 | `App/TunnelChannel/` | - | | TunnelChannelApp | 隧道通道检测 | 海康相机 + VzNL 3D相机 | - | 502→5020 | - | 2D+3D 融合 |
| WheelMeasureApp | 轮毂尺寸测量 | `App/WheelMeasure/` | - | | WheelMeasureApp | 轮毂尺寸测量 | VzNL 3D相机 | - | 502→5020 | - | - |
> **协议说明:**
> - **TCP**:用于与机器人/上位机通信的自定义协议
> - **Modbus TCP**502 为标准端口,由于系统默认不允许非 root 用户监听 502 端口,通过 iptables 映射到 5020
> - **Modbus RTU**:仅 BeltTearingApp 支持,通过串口读取温度传感器数据
## 构建说明 ## 构建说明