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
05e93a91
Commit
05e93a91
authored
Mar 06, 2023
by
yogesh.m
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
2121bfdd
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
16 deletions
+24
-16
.idea/workspace.xml
.idea/workspace.xml
+2
-2
__pycache__/hash_sender.cpython-39.pyc
__pycache__/hash_sender.cpython-39.pyc
+0
-0
asyncua_server.py
asyncua_server.py
+15
-2
hash_receiver.py
hash_receiver.py
+1
-9
hash_sender.py
hash_sender.py
+1
-1
opcua-transmitter.py
opcua-transmitter.py
+5
-2
No files found.
.idea/workspace.xml
View file @
05e93a91
...
@@ -49,7 +49,7 @@
...
@@ -49,7 +49,7 @@
<recent
name=
"D:\opcua-cloning"
/>
<recent
name=
"D:\opcua-cloning"
/>
</key>
</key>
</component>
</component>
<component
name=
"RunManager"
selected=
"Python.
hash_sender
"
>
<component
name=
"RunManager"
selected=
"Python.
opcua-transmitter (1)
"
>
<configuration
name=
"asyncua_server (1)"
type=
"PythonConfigurationType"
factoryName=
"Python"
temporary=
"true"
nameIsGenerated=
"true"
>
<configuration
name=
"asyncua_server (1)"
type=
"PythonConfigurationType"
factoryName=
"Python"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"opcua-cloning"
/>
<module
name=
"opcua-cloning"
/>
<option
name=
"INTERPRETER_OPTIONS"
value=
""
/>
<option
name=
"INTERPRETER_OPTIONS"
value=
""
/>
...
@@ -178,8 +178,8 @@
...
@@ -178,8 +178,8 @@
</configuration>
</configuration>
<recent_temporary>
<recent_temporary>
<list>
<list>
<item
itemvalue=
"Python.hash_sender"
/>
<item
itemvalue=
"Python.opcua-transmitter (1)"
/>
<item
itemvalue=
"Python.opcua-transmitter (1)"
/>
<item
itemvalue=
"Python.hash_sender"
/>
<item
itemvalue=
"Python.opcua_receiver"
/>
<item
itemvalue=
"Python.opcua_receiver"
/>
<item
itemvalue=
"Python.asyncua_server (1)"
/>
<item
itemvalue=
"Python.asyncua_server (1)"
/>
<item
itemvalue=
"Python.asyncua_server"
/>
<item
itemvalue=
"Python.asyncua_server"
/>
...
...
__pycache__/hash_sender.cpython-39.pyc
0 → 100644
View file @
05e93a91
File added
asyncua_server.py
View file @
05e93a91
import
asyncio
import
asyncio
from
asyncua
import
ua
,
Server
from
asyncua
import
ua
,
Server
import
random
import
socket
import
threading
import
threading
localIP
=
"2.2.2.5"
localPort
=
20002
bufferSize
=
1024
UDPServerSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
UDPServerSocket
.
bind
((
localIP
,
localPort
))
class
asyncua_server
():
class
asyncua_server
():
def
__init__
(
self
):
def
__init__
(
self
):
self
.
server
=
None
self
.
server
=
None
...
@@ -39,8 +45,15 @@ class asyncua_server():
...
@@ -39,8 +45,15 @@ class asyncua_server():
# stop the server
# stop the server
await
self
.
server
.
stop
()
await
self
.
server
.
stop
()
asr
=
asyncua_server
()
def
hash_receive
():
while
(
True
):
bytesAddressPair
=
UDPServerSocket
.
recvfrom
(
bufferSize
)
message
=
bytesAddressPair
[
0
]
print
(
message
)
def
st
():
def
st
():
asr
=
asyncua_server
()
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://localhost:4840/myopc/free"
,
"http://klopc.com"
))
hash_receiver.py
View file @
05e93a91
import
socket
import
socket
localIP
=
"2.2.2.5"
localPort
=
20002
bufferSize
=
1024
UDPServerSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
UDPServerSocket
.
bind
((
localIP
,
localPort
))
while
(
True
):
bytesAddressPair
=
UDPServerSocket
.
recvfrom
(
bufferSize
)
message
=
bytesAddressPair
[
0
]
print
(
message
)
\ No newline at end of file
hash_sender.py
View file @
05e93a91
...
@@ -41,5 +41,5 @@ async def get_send_hash():
...
@@ -41,5 +41,5 @@ async def get_send_hash():
UDPClientSocket
.
sendto
(
hierarchy
,
serverAddressPort
)
UDPClientSocket
.
sendto
(
hierarchy
,
serverAddressPort
)
print
(
hierarchy
)
print
(
hierarchy
)
if
__name__
==
'__main__'
:
def
send_hash
()
:
asyncio
.
run
(
get_send_hash
())
asyncio
.
run
(
get_send_hash
())
\ No newline at end of file
opcua-transmitter.py
View file @
05e93a91
import
asyncio
import
asyncio
import
socket
import
socket
import
threading
import
hash_sender
from
asyncua
import
Client
,
Node
from
asyncua
import
Client
,
Node
from
asyncua.common.subscription
import
DataChangeNotif
,
SubHandler
from
asyncua.common.subscription
import
DataChangeNotif
,
SubHandler
...
@@ -51,6 +52,8 @@ async def main() -> None:
...
@@ -51,6 +52,8 @@ async def main() -> None:
# Get a variable node.
# Get a variable node.
node
=
await
get_nodes
(
client
)
node
=
await
get_nodes
(
client
)
# Subscribe data change.
# Subscribe data change.
t1
=
threading
.
Thread
(
target
=
hash_sender
.
send_hash
)
t1
.
start
()
handler
=
MyHandler
()
handler
=
MyHandler
()
subscription
=
await
client
.
create_subscription
(
period
=
0
,
handler
=
handler
)
subscription
=
await
client
.
create_subscription
(
period
=
0
,
handler
=
handler
)
await
subscription
.
subscribe_data_change
(
node
)
await
subscription
.
subscribe_data_change
(
node
)
...
@@ -58,7 +61,7 @@ async def main() -> None:
...
@@ -58,7 +61,7 @@ async def main() -> None:
# Process data change every 100ms
# Process data change every 100ms
while
True
:
while
True
:
await
handler
.
process
()
await
handler
.
process
()
await
asyncio
.
sleep
(
0.
1
)
await
asyncio
.
sleep
(
1
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
asyncio
.
run
(
main
())
asyncio
.
run
(
main
())
...
...
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