OPC-UA:recv(buffersize)函数卡住,没有任何错误/警告消息

发布于 2025-01-09 08:31:45 字数 1788 浏览 0 评论 0原文

有关我的线程相关背景的一些信息:

  • 客户端-服务器连接领域知识:初学者

  • Python程序员:中高级

我面临的问题

使用OPCUA协议将客户端连接到服务器(我使用的工具:opcua python-library和VS-code编辑器)。

问题是如何开始的?

  • 我尝试使用 node.get_value() 方法(其中 node = client.get_node("ns=2;i= 2"))。那么错误是:“没有类型没有名为‘send_request’的方法”。这让我认为套接字连接没有建立。因此,我尝试首先使用 UAClient.connect_socket() 方法建立套接字连接,这使我找到了问题的根源,即以下代码中的最后一个命令行:

< strong>我的代码:

from opcua import Server
from opcua import Client
from opcua import ua
from ua_client import *
from traceback import print_exc
from opcua import Client



name = "OPC_SIMULATION_SERVER" 
addspace = server.register_namespace(name)
node = server.get_objects_node()
Param = node.add_object(addspace, "Parameters")

server = Server() 
url = 'opc.tcp://127.0.0.1:4840' # opc server URL (connection works, checked in in command line with "ping")

server.start()
print("Server started at {}".format(url))

client = Client(url) # create client object
ref = client.uaclient # create UAClient object
# establish socket (to my understanding)
ref._uasocket = UASocketClient(ref._timeout, security_policy=ref.security_policy)
host = client.server_url.hostname
port = client.server_url.port
refsock = ref._uasocket
sock = socket.create_connection((host, port), timeout=refsock.timeout)
sock.settimeout(None) # for blocking (doesn’t cause the error)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
refsock._socket = ua.utils.SocketWrapper(sock)

# ERRATIC LINE: The following command gets stuck without an error/warning message
chunk = refsock._socket.socket.recv(8)
# \==================================================

我应该注意,最初我从节点获取值没有问题。

Some information about my relevant-to-the-thread background:

  • Client-Server connection domain knowledge: Beginner

  • Python-programmer: Mid to advanced level

Problem I am facing:

connecting a Client to a Server using the OPCUA protocol (tool I am using: opcua python-library and VS-code editor).

How did the problem start?

  • I was attempting to use the node.get_value() method (where node = client.get_node("ns=2;i=2")). Then the error is: "None type does not have a method called 'send_request'". This made me think that the socket connection is not established. Therefore, I tried to establish a socket connection first, by using the UAClient.connect_socket() method, which lead me to the origin of the problem, which is the last command line in the following code:

My code:

from opcua import Server
from opcua import Client
from opcua import ua
from ua_client import *
from traceback import print_exc
from opcua import Client



name = "OPC_SIMULATION_SERVER" 
addspace = server.register_namespace(name)
node = server.get_objects_node()
Param = node.add_object(addspace, "Parameters")

server = Server() 
url = 'opc.tcp://127.0.0.1:4840' # opc server URL (connection works, checked in in command line with "ping")

server.start()
print("Server started at {}".format(url))

client = Client(url) # create client object
ref = client.uaclient # create UAClient object
# establish socket (to my understanding)
ref._uasocket = UASocketClient(ref._timeout, security_policy=ref.security_policy)
host = client.server_url.hostname
port = client.server_url.port
refsock = ref._uasocket
sock = socket.create_connection((host, port), timeout=refsock.timeout)
sock.settimeout(None) # for blocking (doesn’t cause the error)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
refsock._socket = ua.utils.SocketWrapper(sock)

# ERRATIC LINE: The following command gets stuck without an error/warning message
chunk = refsock._socket.socket.recv(8)
# \==================================================

I should note that initially I had no problem with getting the value from the node.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文