Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-cloning
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yogesh.m
opcua-cloning
Commits
58d3fa08
Commit
58d3fa08
authored
Mar 09, 2023
by
yogesh.m
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update for reccursion
parent
1c97f698
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
32 deletions
+40
-32
hash_receiver.py
hash_receiver.py
+0
-4
hash_sender.py
hash_sender.py
+39
-26
opcua-transmitter.py
opcua-transmitter.py
+0
-1
opcua_subscriber/opcua_subscribe.py
opcua_subscriber/opcua_subscribe.py
+1
-1
No files found.
hash_receiver.py
deleted
100644 → 0
View file @
1c97f698
import
socket
hash_sender.py
View file @
58d3fa08
...
@@ -3,8 +3,10 @@ import asyncio
...
@@ -3,8 +3,10 @@ import asyncio
import
socket
import
socket
from
time
import
sleep
from
time
import
sleep
import
pickle
import
pickle
import
json
ENDPOINT
=
'opc.tcp://2.2.2.7:53530/OPCUA/SimulationServer'
ENDPOINT
=
'opc.tcp://2.2.2.7:53530/OPCUA/SimulationServer'
NAMESPACE
=
'http://www.prosysopc.com/OPCUA/Simulation
Server
/'
NAMESPACE
=
'http://www.prosysopc.com/OPCUA/Simulation
Nodes
/'
msgFromClient
=
"Hello UDP Server"
msgFromClient
=
"Hello UDP Server"
bytesToSend
=
str
.
encode
(
msgFromClient
)
bytesToSend
=
str
.
encode
(
msgFromClient
)
...
@@ -12,35 +14,46 @@ serverAddressPort = ("2.2.2.5", 20002)
...
@@ -12,35 +14,46 @@ serverAddressPort = ("2.2.2.5", 20002)
bufferSize
=
1024
bufferSize
=
1024
UDPClientSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
UDPClientSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
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
()
node_hierarchy
[
child_disp_name
.
Text
]
=
await
create_node_hierarchy
(
client
,
children_nodes
)
node_hierarchy
[
child_disp_name
.
Text
][
"name"
]
=
child_disp_name
.
Text
if
(
node_class
.
_name_
==
"Variable"
):
datatype
=
await
sub_obj
.
read_data_type_as_variant_type
()
node_hierarchy
[
child_disp_name
.
Text
][
"datatype"
]
=
datatype
.
_value_
else
:
disp_name
=
await
sub_obj
.
read_display_name
()
node_hierarchy
[
disp_name
.
Text
]
=
{}
node_hierarchy
[
disp_name
.
Text
][
"name"
]
=
disp_name
.
Text
if
(
node_class
.
_name_
==
"Variable"
):
datatype
=
await
sub_obj
.
read_data_type_as_variant_type
()
node_hierarchy
[
disp_name
.
Text
][
"datatype"
]
=
datatype
.
_value_
return
node_hierarchy
async
def
get_send_hash
():
async
def
get_send_hash
():
global
nm_no
async
with
Client
(
url
=
ENDPOINT
)
as
client
:
async
with
Client
(
url
=
ENDPOINT
)
as
client
:
root
=
client
.
get_root_node
()
nm_no
=
await
client
.
get_namespace_index
(
NAMESPACE
)
root_objects
=
await
root
.
get_children
()
root_node
=
client
.
get_root_node
()
nm_no
=
await
client
.
get_namespace_index
(
"http://www.prosysopc.com/OPCUA/SimulationNodes/"
)
root_objects
=
await
root_node
.
get_children
()
node_objects
=
root_objects
[
0
]
while
True
:
while
True
:
sleep
(
1
)
node_objects_children
=
await
node_objects
.
get_children
()
# replace with your own node id
individual_node
=
{}
node_hierarchy
=
await
create_node_hierarchy
(
client
,
node_objects_children
)
hierarchy
=
{}
node_hierarchy
[
"hash"
]
=
hash
(
str
(
node_hierarchy
))
Objects
=
await
root_objects
[
0
]
.
get_children
()
json_hierarchy
=
json
.
dumps
(
node_hierarchy
)
for
sub_obj
in
Objects
:
hierarchy
=
pickle
.
dumps
(
json_hierarchy
)
if
(
sub_obj
.
nodeid
.
NamespaceIndex
==
nm_no
):
display_name
=
await
sub_obj
.
read_display_name
()
identifier_type
=
sub_obj
.
nodeid
.
NodeIdType
.
_name_
children
=
await
sub_obj
.
get_children
()
for
ch
in
children
:
identifier
=
ch
.
nodeid
.
Identifier
individual_node
[
identifier
]
=
{}
node_name
=
await
ch
.
read_display_name
()
individual_node
[
identifier
][
"node_name"
]
=
node_name
.
Text
datatype
=
await
ch
.
read_data_type_as_variant_type
()
individual_node
[
identifier
][
"datatype"
]
=
datatype
.
_value_
hierarchy
[
display_name
.
Text
]
=
{}
hierarchy
[
display_name
.
Text
][
"name"
]
=
identifier_type
hierarchy
[
display_name
.
Text
][
"obj"
]
=
pickle
.
dumps
(
individual_node
)
hierarchy
[
"hash"
]
=
hash
(
str
(
hierarchy
))
hierarchy
=
pickle
.
dumps
(
hierarchy
)
UDPClientSocket
.
sendto
(
hierarchy
,
serverAddressPort
)
UDPClientSocket
.
sendto
(
hierarchy
,
serverAddressPort
)
#print(hierarchy)
def
send_hash
():
def
send_hash
():
asyncio
.
run
(
get_send_hash
())
asyncio
.
run
(
get_send_hash
())
\ No newline at end of file
opcua-transmitter.py
View file @
58d3fa08
...
@@ -27,7 +27,6 @@ class MyHandler(SubHandler):
...
@@ -27,7 +27,6 @@ class MyHandler(SubHandler):
while
True
:
while
True
:
[
node
,
value
,
data
]
=
self
.
_queue
.
get_nowait
()
[
node
,
value
,
data
]
=
self
.
_queue
.
get_nowait
()
datatype
=
type
(
value
)
datatype
=
type
(
value
)
print
(
value
)
packet
=
str
(
datatype
)
+
"&"
+
str
(
value
)
+
"&"
+
str
(
node
.
nodeid
.
NamespaceIndex
)
+
"&"
+
str
(
node
.
nodeid
.
Identifier
)
packet
=
str
(
datatype
)
+
"&"
+
str
(
value
)
+
"&"
+
str
(
node
.
nodeid
.
NamespaceIndex
)
+
"&"
+
str
(
node
.
nodeid
.
Identifier
)
UDPClientSocket
.
sendto
(
str
.
encode
(
packet
),
serverAddressPort
)
UDPClientSocket
.
sendto
(
str
.
encode
(
packet
),
serverAddressPort
)
...
...
opcua_subscriber/opcua_subscribe.py
View file @
58d3fa08
...
@@ -461,4 +461,4 @@ class opcua_pack():
...
@@ -461,4 +461,4 @@ class opcua_pack():
self
.
cs
=
self
.
cs
+
1
self
.
cs
=
self
.
cs
+
1
elif
(
datatype
==
"<class 'int'>"
):
elif
(
datatype
==
"<class 'int'>"
):
sock
.
sendall
(
self
.
write_request
(
self
.
SecureChannelId
,
self
.
TokenId
,
self
.
identifier_string
,
self
.
cs
,
int
(
ns
),
int
(
nodeid
),
float
(
val
),
datatype
))
sock
.
sendall
(
self
.
write_request
(
self
.
SecureChannelId
,
self
.
TokenId
,
self
.
identifier_string
,
self
.
cs
,
int
(
ns
),
int
(
nodeid
),
float
(
val
),
datatype
))
self
.
cs
=
self
.
cs
+
1
self
.
cs
=
self
.
cs
+
1
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment