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
2200d746
Commit
2200d746
authored
Mar 06, 2023
by
yogesh.m
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
735a8260
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
19 deletions
+19
-19
__pycache__/asyncua_server.cpython-39.pyc
__pycache__/asyncua_server.cpython-39.pyc
+0
-0
asyncua_server.py
asyncua_server.py
+12
-10
opcua_receiver.py
opcua_receiver.py
+7
-9
opcua_subscriber/__pycache__/opcua_subscribe.cpython-39.pyc
opcua_subscriber/__pycache__/opcua_subscribe.cpython-39.pyc
+0
-0
No files found.
__pycache__/asyncua_server.cpython-39.pyc
0 → 100644
View file @
2200d746
File added
asyncua_server.py
View file @
2200d746
import
asyncio
import
asyncio
from
asyncua
import
ua
,
Server
from
asyncua
import
ua
,
Server
import
random
import
random
import
threading
class
asyncua_server
():
class
asyncua_server
():
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -8,7 +9,8 @@ class asyncua_server():
...
@@ -8,7 +9,8 @@ class asyncua_server():
self
.
idx
=
None
self
.
idx
=
None
async
def
add_object
(
self
,
obj
):
async
def
add_object
(
self
,
obj
):
return
await
self
.
server
.
nodes
.
objects
.
add_object
(
self
.
idx
,
obj
)
print
(
self
.
idx
,
obj
)
return
await
self
.
server
.
nodes
.
objects
.
add_object
(
self
.
idx
,
obj
)
async
def
add_variable
(
self
,
obj
,
var
):
async
def
add_variable
(
self
,
obj
,
var
):
var
=
await
obj
.
add_variable
(
self
.
idx
,
var
,
11
)
var
=
await
obj
.
add_variable
(
self
.
idx
,
var
,
11
)
...
@@ -16,6 +18,7 @@ class asyncua_server():
...
@@ -16,6 +18,7 @@ class asyncua_server():
return
var
return
var
async
def
start_server
(
self
,
url
,
uri
):
async
def
start_server
(
self
,
url
,
uri
):
print
(
url
)
# create a server
# create a server
self
.
server
=
Server
()
self
.
server
=
Server
()
await
self
.
server
.
init
()
await
self
.
server
.
init
()
...
@@ -25,20 +28,19 @@ class asyncua_server():
...
@@ -25,20 +28,19 @@ class asyncua_server():
# create a new address space
# create a new address space
uri
=
uri
uri
=
uri
self
.
idx
=
await
self
.
server
.
register_namespace
(
uri
)
self
.
idx
=
await
self
.
server
.
register_namespace
(
uri
)
# obj = await self.add_object(self.idx,"MyObject")
# var = await self.add_variable(obj,self.idx,"Myvar")
# start the server
await
self
.
server
.
start
()
await
self
.
server
.
start
()
obj
=
self
.
server
.
nodes
.
objects
.
add_object
(
self
.
idx
,
"MyObject"
)
try
:
try
:
# keep the server running until interrupted
# keep the server running until interrupted
while
True
:
while
True
:
#
await
var.write_value(random.randint(1, 100))
#var.write_value(random.randint(1, 100))
await
asyncio
.
sleep
(
1
)
await
asyncio
.
sleep
(
0.
1
)
finally
:
finally
:
# stop the server
# stop the server
await
self
.
server
.
stop
()
await
self
.
server
.
stop
()
if
__name__
==
"__main__"
:
asua
=
asyncua_server
()
asyncio
.
run
(
asua
.
start_server
())
def
st
():
asr
=
asyncua_server
()
asyncio
.
run
(
asr
.
start_server
(
"opc.tcp://192.168.1.10:4840/myopc/free"
,
"http://klopc.com"
))
opcua_receiver.py
View file @
2200d746
import
socket
import
socket
from
opcua
import
Client
,
ua
from
opcua
import
Client
,
ua
from
opcua_subscriber.opcua_subscribe
import
*
from
opcua_subscriber.opcua_subscribe
import
*
from
asyncua_server
import
asyncua_server
from
asyncua_server
import
st
import
asyncio
# client = Client("opc.tcp:2.2.2.7:53530/OPCUA/SimulationServer")
import
threading
# client.connect()
localIP
=
"2.2.2.5"
localIP
=
"2.2.2.5"
...
@@ -22,16 +21,15 @@ UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
...
@@ -22,16 +21,15 @@ UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
# Bind to address and ip
# Bind to address and ip
UDPServerSocket
.
bind
((
localIP
,
localPort
))
#
UDPServerSocket.bind((localIP, localPort))
print
(
"UDP server up and listening"
)
print
(
"UDP server up and listening"
)
t1
=
threading
.
Thread
(
target
=
st
,
args
=
())
t1
.
start
()
print
(
"here"
)
opua
=
opcua_pack
()
opua
=
opcua_pack
()
sock
=
opua
.
connect
(
"opc.tcp://2.2.2.5:53530/OPCUA/SimulationServer"
)
sock
=
opua
.
connect
(
"opc.tcp://2.2.2.5:53530/OPCUA/SimulationServer"
)
as_server
=
asyncua_server
()
as_server
.
start_server
(
"opc.tcp://localhost:4840/myopc/free"
,
"http://klopc.com"
)
as_server
.
add_object
(
"Myobj_"
)
while
(
True
):
while
(
True
):
bytesAddressPair
=
UDPServerSocket
.
recvfrom
(
bufferSize
)
bytesAddressPair
=
UDPServerSocket
.
recvfrom
(
bufferSize
)
message
=
bytesAddressPair
[
0
]
message
=
bytesAddressPair
[
0
]
...
...
opcua_subscriber/__pycache__/opcua_subscribe.cpython-39.pyc
View file @
2200d746
No preview for this file type
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