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
26e0a8d7
Commit
26e0a8d7
authored
Mar 07, 2023
by
yogesh.m
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
0c317886
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
9 deletions
+25
-9
asyncua_server.py
asyncua_server.py
+20
-5
opcua_receiver.py
opcua_receiver.py
+2
-1
opcua_subscriber/opcua_subscribe.py
opcua_subscriber/opcua_subscribe.py
+3
-3
No files found.
asyncua_server.py
View file @
26e0a8d7
...
...
@@ -3,6 +3,7 @@ import pickle
from
asyncua
import
ua
,
Server
import
socket
import
threading
from
time
import
sleep
localIP
=
"2.2.2.5"
localPort
=
20002
...
...
@@ -15,9 +16,19 @@ class asyncua_server():
self
.
server
=
None
self
.
idx
=
None
async
def
add_object
(
self
,
obj
):
print
(
self
.
idx
,
obj
)
return
await
self
.
server
.
nodes
.
objects
.
add_object
(
self
.
idx
,
obj
)
async
def
add_object
(
self
,
obj
,
hierarchy
):
print
(
hierarchy
[
obj
])
if
(
hierarchy
[
obj
][
"name"
]
==
"String"
):
var_obj
=
await
self
.
server
.
nodes
.
objects
.
add_folder
(
self
.
idx
,
obj
)
val_array
=
pickle
.
loads
(
hierarchy
[
obj
][
"obj"
])
if
(
val_array
[
"datatype"
]
==
11
):
var
=
await
var_obj
.
add_variable
(
ua
.
NodeId
(
val_array
[
"identifier"
],
3
),
val_array
[
"node_name"
],
ua
.
NodeId
(
ua
.
ObjectIds
.
Double
))
await
var
.
set_writable
()
if
(
val_array
[
"datatype"
]
==
6
):
var
=
await
var_obj
.
add_variable
(
ua
.
NodeId
(
val_array
[
"identifier"
],
3
),
val_array
[
"node_name"
],
ua
.
NodeId
(
ua
.
ObjectIds
.
Int32
))
await
var
.
set_writable
()
else
:
await
self
.
server
.
nodes
.
objects
.
add_folder
(
self
.
idx
,
obj
)
async
def
add_variable
(
self
,
obj
,
var
):
var
=
await
obj
.
add_variable
(
self
.
idx
,
var
,
11
)
...
...
@@ -50,16 +61,20 @@ asr = asyncua_server()
def
hash_receive
():
prev_hash
=
0
sleep
(
5
)
while
(
True
):
bytesAddressPair
=
UDPServerSocket
.
recvfrom
(
bufferSize
)
message
=
bytesAddressPair
[
0
]
hierarchy
=
pickle
.
loads
(
message
)
print
(
hierarchy
[
"hash"
])
if
(
prev_hash
!=
hierarchy
[
"hash"
]):
print
(
"changed"
)
for
object
in
hierarchy
:
if
(
object
!=
"hash"
):
display_name
=
object
asyncio
.
run
(
asr
.
add_object
(
object
,
hierarchy
))
prev_hash
=
hierarchy
[
"hash"
]
def
st
():
t1
=
threading
.
Thread
(
target
=
hash_receive
)
t1
.
start
()
asyncio
.
run
(
asr
.
start_server
(
"opc.tcp://
localhost:4840
/myopc/free"
,
"http://klopc.com"
))
asyncio
.
run
(
asr
.
start_server
(
"opc.tcp://
2.2.2.5:53531
/myopc/free"
,
"http://klopc.com"
))
opcua_receiver.py
View file @
26e0a8d7
...
...
@@ -26,9 +26,10 @@ UDPServerSocket.bind((localIP, localPort))
print
(
"UDP server up and listening"
)
t1
=
threading
.
Thread
(
target
=
st
,
args
=
())
t1
.
start
()
sleep
(
10
)
print
(
"here"
)
opua
=
opcua_pack
()
sock
=
opua
.
connect
(
"opc.tcp://2.2.2.5:5353
0/OPCUA/SimulationServer
"
)
sock
=
opua
.
connect
(
"opc.tcp://2.2.2.5:5353
1/myopc/free
"
)
while
(
True
):
bytesAddressPair
=
UDPServerSocket
.
recvfrom
(
bufferSize
)
...
...
opcua_subscriber/opcua_subscribe.py
View file @
26e0a8d7
...
...
@@ -141,7 +141,7 @@ class opcua_pack():
DiscoveryProfileUri
=
binascii
.
unhexlify
(
"ffffffff"
)
ArraySize
=
0
ServerUri
=
binascii
.
unhexlify
(
"ffffffff"
)
EndpointUrl
=
"opc.tcp://2.2.2.
7:53530/OPCUA/SimulationServer
"
EndpointUrl
=
"opc.tcp://2.2.2.
5:53531/myopc/free
"
EndpointUrllen
=
len
(
EndpointUrl
.
encode
())
.
to_bytes
(
4
,
byteorder
=
"little"
)
SessionName
=
"Pure Python Client Session1"
SessionNamelen
=
len
(
SessionName
.
encode
())
.
to_bytes
(
4
,
byteorder
=
"little"
)
...
...
@@ -421,7 +421,7 @@ class opcua_pack():
return
session
def
connect
(
self
,
address
):
server_address
=
(
'2.2.2.5'
,
5353
0
)
server_address
=
(
'2.2.2.5'
,
5353
1
)
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
.
connect
(
server_address
)
message
=
self
.
helf
(
address
)
...
...
@@ -456,6 +456,6 @@ class opcua_pack():
if
(
datatype
==
"<class 'float'>"
):
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
el
se
:
el
if
(
datatype
==
"<class 'int'>"
)
:
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
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