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
d5eda3b4
Commit
d5eda3b4
authored
Mar 17, 2023
by
yogesh.m
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
3b920c2c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 addition
and
103 deletions
+1
-103
opcua-transmitter.py
opcua-transmitter.py
+0
-102
opcua_subscriber/opcua_subscribe.py
opcua_subscriber/opcua_subscribe.py
+1
-1
No files found.
opcua-transmitter.py
deleted
100644 → 0
View file @
3b920c2c
import
asyncio
import
socket
import
threading
import
hash_sender
from
asyncua
import
Client
,
Node
from
asyncua.common.subscription
import
DataChangeNotif
,
SubHandler
import
yaml
yamlfile
=
open
(
"opc_ua_transmitter_config.yaml"
)
data
=
yaml
.
load
(
yamlfile
,
Loader
=
yaml
.
FullLoader
)
server_hash_udp_ip
=
data
[
"configuration"
][
"server_hash_udp_ip"
]
server_hash_udp_port
=
data
[
"configuration"
][
"server_hash_udp_port"
]
server_udp_ip
=
data
[
"configuration"
][
"server_udp_ip"
]
server_udp_port
=
int
(
data
[
"configuration"
][
"server_udp_port"
])
serverAddressPort
=
(
server_udp_ip
,
server_udp_port
)
ENDPOINT
=
data
[
"configuration"
][
"endpoint"
]
NAMESPACE
=
data
[
"configuration"
][
"namespace"
]
bufferSize
=
1024
UDPClientSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
nm_no
=
''
class
MyHandler
(
SubHandler
):
def
__init__
(
self
):
self
.
_queue
=
asyncio
.
Queue
()
def
datachange_notification
(
self
,
node
:
Node
,
value
,
data
:
DataChangeNotif
)
->
None
:
self
.
_queue
.
put_nowait
([
node
,
value
,
data
])
async
def
process
(
self
)
->
None
:
try
:
while
True
:
[
node
,
value
,
data
]
=
self
.
_queue
.
get_nowait
()
datatype
=
type
(
value
)
print
(
value
)
packet
=
str
(
datatype
)
+
"&"
+
str
(
value
)
+
"&"
+
str
(
node
.
nodeid
.
NamespaceIndex
)
+
"&"
+
str
(
node
.
nodeid
.
Identifier
)
UDPClientSocket
.
sendto
(
str
.
encode
(
packet
),
serverAddressPort
)
except
asyncio
.
QueueEmpty
:
pass
variables
=
[]
async
def
get_nodes
(
client
,
node_objects
):
for
sub_obj
in
node_objects
:
if
(
"ns="
+
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
)):
await
get_nodes
(
client
,
children_nodes
)
if
(
node_class
.
_name_
==
"Variable"
):
variables
.
append
(
sub_obj
)
else
:
if
(
node_class
.
_name_
==
"Variable"
):
variables
.
append
(
sub_obj
)
return
variables
async
def
main
()
->
None
:
global
nm_no
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
:
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
):
global
server_hash_udp_ip
global
server_hash_udp_port
global
server_udp_ip
global
server_hash_udp_port
global
server_udp_ip
global
server_udp_port
global
serverAddressPort
global
ENDPOINT
global
NAMESPACE
server_hash_udp_ip
=
_server_hash_udp_ip
server_hash_udp_port
=
_server_hash_udp_port
server_udp_ip
=
_server_udp_ip
server_udp_port
=
_server_udp_port
serverAddressPort
=
(
_server_udp_ip
,
_server_udp_port
)
ENDPOINT
=
_ENDPOINT
NAMESPACE
=
_NAMESPACE
asyncio
.
run
(
main
())
if
__name__
==
"__main__"
:
asyncio
.
run
(
main
())
opcua_subscriber/opcua_subscribe.py
View file @
d5eda3b4
...
...
@@ -426,7 +426,7 @@ class opcua_pack():
def
connect
(
self
,
address
):
host
,
port
=
address
.
split
(
"/"
)[
2
]
.
split
(
":"
)
server_address
=
(
host
,
int
(
port
))
server_address
=
(
socket
.
gethostbyname
(
host
)
,
int
(
port
))
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
.
connect
(
server_address
)
message
=
self
.
helf
(
address
)
...
...
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