2017-04-18 24 views
1

Pythonを使用したOPC UAサーバークライアントプログラムの作成方法。 私はこのリンクを見つけました - https://github.com/FreeOpcUa/python-opcua/tree/master/examples 私はコードの流れを得ることができません。誰かが同じような関連文書を持っている場合は、あなたの提案をしてください。 plsはそれを共有します。OPC UAプロトコルを使用したPythonでのサーバークライアントプログラミング

+0

こんにちは。私はあなたが言及した同じリンクを参照しています。走ってしまいましたか? –

答えて

0

正確に何をしたいですか?構造はむしろあなたがそれのスイングを得るoncesを発行しています。それがインストールされていますOncesは、サーバーを実行して、彼はこのGUIは、おそらくサーバーの構造を見るために大いに役立つだろう

opcua-client 

をコマンドラインwitthそれをチェック。

opcuaサーバがノードの組み合わせから存在します。そのうちのいくつかは、プログラミングする場合、これらの基本的なノードの多くが使用して受信することができますあなたが を実行する最も基本的なOPCサーバに表示される標準ノードです:

server.nodes#.<some node use your IDE> 

をあなたがそれらを見つけるために必要なすべてのカスタム・ノードの場合は、あなたはget get childを使ってこれを行うことができます。例:

# To get the root node ALL other nodes are a child fro; this one eventually 
root = server.get_root_node() 
# To get a child: 
root.get_child("0:Objects") #Objects is one of those basic nodes 
# You can get a child from a path 
# Once again first study the tree with the opcua-client gui 
# This gui is installed automatically and under the commane opcua-client 
root.get_child(["0:Objects", "0:Server"]) 

# The above will get the child of Objects called Server 
# directly starting at the root node 

これで、自分で子ノードを作成できます。あなたが通常に子を追加するノードに移動します。

# The Objects node 
# Later you'll probably want to put that all in 1 line 
objects = server.nodes.objects 
id, name, type = 2, "testName", None 
test = objects.add_object(id, name, type) 
# This will add a object named testName to the objects node 
# To acces this node again we can use it's id 
server.get_node(test.nodeid) 
# I know this will return test again. 
# However the ua methods "parent' parameter is this nodeid so can come in very handy 

作成UA方法は、おそらくまた、サーバーの重要な課題であることを行っています。

@uamethod 
def methode(parent, input): 
    print(input) # You can do all things here offcourse 

server.nodes.objects.add_method(0, "myMethod", methode, ua.VariantType.ByteString, None) 

これは、オブジェクトノード

0にメソッドを追加しますが、あなたがそれを与えることを望むIDです。私は実際にあなたが選ぶべき数字を説明することはできません...私は通常2を選択します...

"mymethod"はノードのget_childメソッドとcall_methodメソッドでそれを見つけることができるブラウズ名になります

方法はあなたの方法をオフコースです。

ua.VariantType私functiondが、これはあなたが行うことができ、ほとんどの基本を理解する上であなたにビットを助けた

希望を持っていませんでした...

なし上記と同じではありませんが、outputargs inputargsのデータを解析するために必要とされますfreeopcua library

関連する問題