我正在使用freeOpcua来编写一个简单的客户端示例。我首先在我的笔记本电脑上测试了它,运行它的服务器代码,然后在raspberry pi3中运行linux中的客户端代码。所以我能够连接到服务器。FreeOPCUA python客户端示例
现在我有一台运行B & R Server的PLC。我需要连接到此服务器并获取属性值,但每当我尝试连接它时,都会显示connection refused error
。服务器运行正常,因为我在Windows上使用客户端软件进行了测试,但未在Linux中进行连接。我正在使用freeopcua客户端示例连接到服务器。
是否需要启用我试图与之通信的端口?
有没有人有这方面的经验。请帮忙。谢谢。
编辑:
的IP地址192.168.1.21是,端口号是135,我做这样的事情如下:
client = Client("opc.tcp://192.168.1.21:135/")
client.connect()
#This gives error of connection refused.
我打开client.connect(),并发现它具有以下功能:
connect_socket()
send_hello()
open_secure_channel()
create_session()
activate_session()
所以不是做client.connect()
我做client.connect_socket()
所以就ok了,并没有给出任何错误的。然后我print(client.get_root_node())
它告诉我Node(TwoByteNodeId(i=84))
和print(client.get_server_node())
它显示Node(FourByteNodeId(i=2253))
。这些价值是什么。我能否认为我可以通过执行client.connect_socket()
来连接到服务器。
当我试图用client.get_endpoints()
得到端点它给了我下面的错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "opcua/client/client.py", line 299, in get_endpoints
return self.uaclient.get_endpoints(params)
File "opcua/client/ua_client.py", line 323, in get_endpoints
data = self._uasocket.send_request(request)
File "opcua/client/ua_client.py", line 76, in send_request
data = future.result(self.timeout)
File "/usr/local/lib/python2.7/dist-packages/concurrent/futures/_base.py",
line 431, in result
raise TimeoutError()
concurrent.futures._base.TimeoutError
此外,当我试图做open_secure_channel()
或create_session()
或任何其他它给了我上面的错误。
是否还有更多的错误信息可用?你能显示服务器返回的端点吗? –
@KevinHerron请看编辑 –
那些获得节点方法并不需要你连接,他们只是建立NodeIds。你有错误的IP /端口或服务器没有运行或允许连接。拒绝连接是连接被拒绝。 –