Commit 301578d1 authored by yogesh.m's avatar yogesh.m

update

parent bab15ac6
......@@ -14,9 +14,9 @@
<change beforePath="$PROJECT_DIR$/build/main/main.pkg" beforeDir="false" afterPath="$PROJECT_DIR$/build/main/main.pkg" afterDir="false" />
<change beforePath="$PROJECT_DIR$/build/main/warn-main.txt" beforeDir="false" afterPath="$PROJECT_DIR$/build/main/warn-main.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/build/main/xref-main.html" beforeDir="false" afterPath="$PROJECT_DIR$/build/main/xref-main.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dist/klopcua cloner.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.spec" beforeDir="false" afterPath="$PROJECT_DIR$/main.spec" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dist/opcua_cloner.exe" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/hash_sender.py" beforeDir="false" afterPath="$PROJECT_DIR$/hash_sender.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/opcua_transmitter.py" beforeDir="false" afterPath="$PROJECT_DIR$/opcua_transmitter.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -62,7 +62,7 @@
<recent name="D:\opcua-cloning" />
</key>
</component>
<component name="RunManager" selected="Python.main">
<component name="RunManager" selected="Python.opcua_transmitter">
<configuration name="asyncua_server (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="opcua-cloning" />
<option name="INTERPRETER_OPTIONS" value="" />
......@@ -84,7 +84,7 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="asyncua_server" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="hash_sender" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="opcua-cloning" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
......@@ -96,7 +96,7 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="D:\opcua-cloning\asyncua_server.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/hash_sender.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
......@@ -105,7 +105,7 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="hash_sender" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="opcua-cloning" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
......@@ -117,7 +117,7 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/hash_sender.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
......@@ -126,7 +126,7 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<configuration name="opcua-transmitter (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="opcua-cloning" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
......@@ -138,7 +138,7 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/opcua-transmitter.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
......@@ -147,7 +147,7 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="opcua-transmitter (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="opcua_receiver" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="opcua-cloning" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
......@@ -159,7 +159,7 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/opcua-transmitter.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/opcua_receiver.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
......@@ -168,7 +168,7 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="opcua_receiver" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="opcua_transmitter" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="opcua-cloning" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
......@@ -180,7 +180,7 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/opcua_receiver.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/opcua_transmitter.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
......@@ -191,11 +191,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.opcua_transmitter" />
<item itemvalue="Python.hash_sender" />
<item itemvalue="Python.opcua-transmitter (1)" />
<item itemvalue="Python.opcua_receiver" />
<item itemvalue="Python.hash_sender" />
<item itemvalue="Python.asyncua_server (1)" />
<item itemvalue="Python.asyncua_server" />
</list>
</recent_temporary>
</component>
......@@ -220,5 +220,6 @@
</entry>
</map>
</option>
<option name="oldMeFiltersMigrated" value="true" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
No preview for this file type
No preview for this file type
......@@ -16,11 +16,11 @@ IMPORTANT: Do NOT post this list to the issue-tracker. Use it as a basis for
missing module named pyimod02_importers - imported by C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgutil.py (top-level), C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgres.py (top-level)
missing module named StringIO - imported by six (conditional), pkg_resources._vendor.six (conditional)
missing module named 'org.python' - imported by pickle (optional), xml.sax (delayed, conditional)
missing module named org - imported by pickle (optional)
missing module named _posixsubprocess - imported by subprocess (optional), multiprocessing.util (delayed)
missing module named grp - imported by shutil (optional), tarfile (optional), pathlib (delayed, optional), subprocess (optional)
missing module named pwd - imported by posixpath (delayed, conditional), shutil (optional), tarfile (optional), pathlib (delayed, conditional, optional), subprocess (optional), netrc (delayed, conditional), getpass (delayed), http.server (delayed, optional), webbrowser (delayed), distutils.util (delayed, conditional, optional)
missing module named posix - imported by os (conditional, optional), shutil (conditional)
missing module named posix - imported by shutil (conditional), os (conditional, optional)
missing module named resource - imported by posix (top-level)
missing module named termios - imported by getpass (optional), tty (top-level)
missing module named _frozen_importlib_external - imported by importlib._bootstrap (delayed), importlib (optional), importlib.abc (optional), zipimport (top-level)
......@@ -29,7 +29,7 @@ missing module named pep517 - imported by importlib.metadata (delayed)
missing module named readline - imported by cmd (delayed, conditional, optional), code (delayed, conditional, optional), pdb (delayed, optional)
missing module named __builtin__ - imported by pkg_resources._vendor.pyparsing (conditional)
missing module named ordereddict - imported by pkg_resources._vendor.pyparsing (optional)
missing module named org - imported by copy (optional)
missing module named 'org.python' - imported by copy (optional), xml.sax (delayed, conditional)
missing module named _manylinux - imported by pkg_resources._vendor.packaging.tags (delayed, optional)
missing module named 'pkg_resources.extern.pyparsing' - imported by pkg_resources._vendor.packaging.markers (top-level), pkg_resources._vendor.packaging.requirements (top-level)
missing module named 'win32com.shell' - imported by pkg_resources._vendor.appdirs (conditional, optional)
......
......@@ -323,7 +323,7 @@ imported by:
<a target="code" href="" type="text/plain"><tt>'org.python'</tt></a>
<span class="moduletype">MissingModule</span> <div class="import">
imported by:
<a href="#pickle">pickle</a>
<a href="#copy">copy</a>
&#8226; <a href="#xml.sax">xml.sax</a>
</div>
......@@ -4991,8 +4991,8 @@ imported by:
<a target="code" href="///C:/users/admin/appdata/local/programs/python/python39/lib/copy.py" type="text/plain"><tt>copy</tt></a>
<span class="moduletype">SourceModule</span> <div class="import">
imports:
<a href="#copyreg">copyreg</a>
&#8226; <a href="#org">org</a>
<a href="#'org.python'">'org.python'</a>
&#8226; <a href="#copyreg">copyreg</a>
&#8226; <a href="#types">types</a>
&#8226; <a href="#weakref">weakref</a>
......@@ -13415,7 +13415,7 @@ imported by:
<a target="code" href="" type="text/plain"><tt>org</tt></a>
<span class="moduletype">MissingModule</span> <div class="import">
imported by:
<a href="#copy">copy</a>
<a href="#pickle">pickle</a>
</div>
......@@ -13651,14 +13651,14 @@ imported by:
<a target="code" href="///C:/users/admin/appdata/local/programs/python/python39/lib/pickle.py" type="text/plain"><tt>pickle</tt></a>
<span class="moduletype">SourceModule</span> <div class="import">
imports:
<a href="#'org.python'">'org.python'</a>
&#8226; <a href="#_compat_pickle">_compat_pickle</a>
<a href="#_compat_pickle">_compat_pickle</a>
&#8226; <a href="#_pickle">_pickle</a>
&#8226; <a href="#codecs">codecs</a>
&#8226; <a href="#copyreg">copyreg</a>
&#8226; <a href="#functools">functools</a>
&#8226; <a href="#io">io</a>
&#8226; <a href="#itertools">itertools</a>
&#8226; <a href="#org">org</a>
&#8226; <a href="#pprint">pprint</a>
&#8226; <a href="#re">re</a>
&#8226; <a href="#struct">struct</a>
......
......@@ -7,51 +7,56 @@ import json
nm_no = None
async def create_node_hierarchy(client, node_objects):
node_hierarchy={}
for sub_obj in node_objects:
if("ns="+str(nm_no)+";" in str(sub_obj)):
node = client.get_node(sub_obj)
children_nodes = await node.get_children()
identifier = str(children_nodes[0].nodeid.Identifier) if children_nodes else ""
node_class = await sub_obj.read_node_class()
if (identifier not in str(sub_obj)):
child_disp_name = await sub_obj.read_display_name()
identifier_name = sub_obj.nodeid.Identifier
node_hierarchy[identifier_name] = await create_node_hierarchy(client, children_nodes)
node_hierarchy[identifier_name]["name"] = child_disp_name.Text
node_hierarchy[identifier_name]["type"] = node_class._value_
if (node_class._name_ == "Variable"):
datatype = await sub_obj.read_data_type_as_variant_type()
node_hierarchy[identifier_name]["datatype"] = datatype._value_
else:
disp_name = await sub_obj.read_display_name()
identifier_name = sub_obj.nodeid.Identifier
node_hierarchy[identifier_name] = {}
node_hierarchy[identifier_name]["name"] = disp_name.Text
node_hierarchy[identifier_name]["type"] = node_class._value_
if (node_class._name_ == "Variable"):
datatype = await sub_obj.read_data_type_as_variant_type()
node_hierarchy[identifier_name]["datatype"] = datatype._value_
return node_hierarchy
class Hash_Sender():
def __init__(self):
self.hash = ""
async def get_send_hash(ENDPOINT,NAMESPACE,server_hash_udp_ip,server_hash_udp_port):
global nm_no
serverAddressPort = (server_hash_udp_ip, server_hash_udp_port)
UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
async with Client(url=ENDPOINT) as client:
nm_no=await client.get_namespace_index(NAMESPACE)
root_node = client.get_root_node()
root_objects = await root_node.get_children()
node_objects = root_objects[0]
while True:
node_objects_children = await node_objects.get_children() # replace with your own node id
node_hierarchy = await create_node_hierarchy(client, node_objects_children)
node_hierarchy["hash"] = hash(str(node_hierarchy))
node_hierarchy["namespace_idx"]=nm_no
json_hierarchy = json.dumps(node_hierarchy)
binary_data = json_hierarchy.encode()
UDPClientSocket.sendto(binary_data, serverAddressPort)
async def create_node_hierarchy(self,client, node_objects):
node_hierarchy={}
for sub_obj in node_objects:
if("ns="+str(nm_no)+";" in str(sub_obj)):
node = client.get_node(sub_obj)
children_nodes = await node.get_children()
identifier = str(children_nodes[0].nodeid.Identifier) if children_nodes else ""
node_class = await sub_obj.read_node_class()
if (identifier not in str(sub_obj)):
child_disp_name = await sub_obj.read_display_name()
identifier_name = sub_obj.nodeid.Identifier
node_hierarchy[identifier_name] = await self.create_node_hierarchy(client, children_nodes)
node_hierarchy[identifier_name]["name"] = child_disp_name.Text
node_hierarchy[identifier_name]["type"] = node_class._value_
if (node_class._name_ == "Variable"):
datatype = await sub_obj.read_data_type_as_variant_type()
node_hierarchy[identifier_name]["datatype"] = datatype._value_
else:
disp_name = await sub_obj.read_display_name()
identifier_name = sub_obj.nodeid.Identifier
node_hierarchy[identifier_name] = {}
node_hierarchy[identifier_name]["name"] = disp_name.Text
node_hierarchy[identifier_name]["type"] = node_class._value_
if (node_class._name_ == "Variable"):
datatype = await sub_obj.read_data_type_as_variant_type()
node_hierarchy[identifier_name]["datatype"] = datatype._value_
return node_hierarchy
def send_hash(Endpoint,Namespace,server_hash_udp_ip,server_hash_udp_port):
asyncio.run(get_send_hash(Endpoint,Namespace,server_hash_udp_ip,server_hash_udp_port))
\ No newline at end of file
async def get_send_hash(self,ENDPOINT,NAMESPACE,server_hash_udp_ip,server_hash_udp_port):
global nm_no
serverAddressPort = (server_hash_udp_ip, server_hash_udp_port)
UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
async with Client(url=ENDPOINT) as client:
nm_no=await client.get_namespace_index(NAMESPACE)
root_node = client.get_root_node()
root_objects = await root_node.get_children()
node_objects = root_objects[0]
while True:
node_objects_children = await node_objects.get_children() # replace with your own node id
node_hierarchy = await self.create_node_hierarchy(client, node_objects_children)
self.hash = node_hierarchy["hash"] = hash(str(node_hierarchy))
node_hierarchy["namespace_idx"]=nm_no
json_hierarchy = json.dumps(node_hierarchy)
binary_data = json_hierarchy.encode()
UDPClientSocket.sendto(binary_data, serverAddressPort)
def send_hash(self,Endpoint,Namespace,server_hash_udp_ip,server_hash_udp_port):
asyncio.run(self.get_send_hash(Endpoint,Namespace,server_hash_udp_ip,server_hash_udp_port))
return self.hash
\ No newline at end of file
import asyncio
import socket
import threading
import hash_sender
from hash_sender import Hash_Sender
from asyncua import Client, Node
from asyncua.common.subscription import DataChangeNotif, SubHandler
import yaml
......@@ -60,23 +60,44 @@ async def get_nodes(client,node_objects):
return variables
async def main() -> None:
hash_changed=False
async def subscribe_node():
global nm_no
async with Client(url=ENDPOINT) as client:
nm_no = str(await client.get_namespace_index(NAMESPACE))
global hash_changed
object_root_node = client.get_objects_node()
objects = await object_root_node.get_children()
node = await get_nodes(client, objects)
handler = MyHandler()
subscription = await client.create_subscription(period=0, handler=handler)
await subscription.subscribe_data_change(node)
while True and not hash_changed:
await handler.process()
await asyncio.sleep(0.01)
hash_changed=False
def subscribe_to_node():
asyncio.run(subscribe_node())
async def main() -> None:
hs=Hash_Sender()
global hash_changed
prev_hash=""
try:
async with Client(url=ENDPOINT) as client:
nm_no = str(await client.get_namespace_index(NAMESPACE))
object_root_node = client.get_objects_node()
objects = await object_root_node.get_children()
node = await get_nodes(client,objects)
t1=threading.Thread(target=hash_sender.send_hash,args=(ENDPOINT,NAMESPACE,server_hash_udp_ip,server_hash_udp_port,))
t1.start()
handler = MyHandler()
subscription = await client.create_subscription(period=0, handler=handler)
await subscription.subscribe_data_change(node)
while True:
await handler.process()
await asyncio.sleep(0.01)
except:
t1=threading.Thread(target=hs.send_hash,args=(ENDPOINT,NAMESPACE,server_hash_udp_ip,server_hash_udp_port,))
t1.start()
while True:
hash=hs.hash
if(hash!=prev_hash and not hash_changed):
prev_hash=hash
hash_changed = True
while(hash_changed):
hash_changed = False
t2=threading.Thread(target=subscribe_to_node,args=())
t2.start()
except Exception:
print("No connection found for opcua server, check if the server is active")
def transmitter_main(_server_hash_udp_ip,_server_hash_udp_port,_server_udp_ip,_server_udp_port,_ENDPOINT,_NAMESPACE):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment