代码之家  ›  专栏  ›  技术社区  ›  S Andrew

FreeOPCUA python客户端示例

  •  2
  • S Andrew  · 技术社区  · 8 年前

    freeOpcua 编写一个简单的客户端示例。我首先在我的笔记本电脑上测试了这一点,运行服务器代码,然后在raspberry pi3中运行linux中的客户端代码。所以我可以连接到服务器。

    connection refused error . 服务器运行良好,因为我在windows上使用客户端软件进行了测试,但没有在linux上连接。我正在使用freeopcua客户端示例连接到服务器。

    有人有这方面的经验吗。请帮忙。谢谢

    编辑:

    client = Client("opc.tcp://192.168.1.21:135/")
    client.connect()
    #This gives error of connection refused.
    

    我打开了客户端。connect()并发现它具有以下函数:

    connect_socket()
    send_hello()
    open_secure_channel()
    create_session()
    activate_session()
    

    client.connect() 我做的 client.connect_socket() print(client.get_root_node()) Node(TwoByteNodeId(i=84)) print(client.get_server_node()) Node(FourByteNodeId(i=2253)) . 这些值是什么。我可以认为我可以通过执行以下操作连接到服务器吗 客户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() 或者它给了我上述错误。

    1 回复  |  直到 8 年前
        1
  •  2
  •   joeb    8 年前

    我也有同样的问题。我发现Hello消息设置了 MaxMessageSize MaxChunkCount 到0。我改变了 freeopcua 代码,使其设置为与 UaExpert ,它成功了。

    弗里奥普库 freeopcua/ua/uaprotocol_hand.py ,我更改了 初始化

    class Hello(uatypes.FrozenClass):
    
        def __init__(self):
            self.ProtocolVersion = 0
            self.ReceiveBufferSize = 65536
            self.SendBufferSize = 65536
            self.MaxMessageSize = 16777216
            self.MaxChunkCount = 5000
            self.EndpointUrl = ""
            self._freeze = True
    

    如果您不知道如何编辑python包,我的位于此处: C:\Users\username\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\opcua\ua

    基本上是你的 python_directory\Lib\site-packages\opcua\ua