You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python 3.10.9与Matrikon仿真服务器连接失败问题求助

Python连接Matrikon OPC仿真服务器的问题解决

问题概述

尝试用Python连接Matrikon OPC仿真服务器时,因端口错误导致连接被拒绝,同时不清楚服务器默认端口配置。

代码与报错信息

原Python代码

import opcua
c = opcua.Client("opc.tcp://localhost:53530/Matrikon.OPC.Simulation.1")
c.connect()

报错信息

Discovery Error: [WinError 10061] No connection could be made because the target machine actively refused it

服务器配置确认

从提供的Matrikon服务器截图可知:

  • Matrikon OPC仿真服务器的OPC UA默认端口为4840,而非代码中使用的53530
  • 服务器的OPC UA服务处于正常运行状态

解决步骤

  1. 修正连接URL:将代码中的端口替换为4840,Matrikon UA服务器的标准端点格式为opc.tcp://localhost:4840
  2. 修改后的代码示例:
import opcua
# 使用正确的OPC UA端口
client = opcua.Client("opc.tcp://localhost:4840")
try:
    client.connect()
    print("连接成功")
    # 可在此添加后续操作,比如读取节点数据
finally:
    client.disconnect()
  1. 额外检查项:确保Matrikon服务器的防火墙允许4840端口的TCP连接,且该端口未被其他进程占用

内容的提问来源于stack exchange,提问作者Engr. Khuram Shahzad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 15:18:14