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
49ee43c7
Commit
49ee43c7
authored
Mar 02, 2023
by
yogesh.m
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
f3d65857
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
23 deletions
+131
-23
.idea/workspace.xml
.idea/workspace.xml
+63
-1
opcua-client.py
opcua-client.py
+68
-22
No files found.
.idea/workspace.xml
View file @
49ee43c7
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"RunManager"
>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"e733891a-c063-4f94-92d6-4559e921107b"
name=
"Default Changelist"
comment=
""
/>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
<option
name=
"HIGHLIGHT_CONFLICTS"
value=
"true"
/>
<option
name=
"HIGHLIGHT_NON_ACTIVE_CHANGELIST"
value=
"false"
/>
<option
name=
"LAST_RESOLUTION"
value=
"IGNORE"
/>
</component>
<component
name=
"Git.Settings"
>
<option
name=
"RECENT_GIT_ROOT_PATH"
value=
"$PROJECT_DIR$"
/>
</component>
<component
name=
"ProjectId"
id=
"2MBBW17AOFLvAzWG4Yg12wAh3jz"
/>
<component
name=
"ProjectViewState"
>
<option
name=
"hideEmptyMiddlePackages"
value=
"true"
/>
<option
name=
"showLibraryContents"
value=
"true"
/>
</component>
<component
name=
"PropertiesComponent"
>
<property
name=
"RunOnceActivity.OpenProjectViewOnStart"
value=
"true"
/>
<property
name=
"RunOnceActivity.ShowReadmeOnStart"
value=
"true"
/>
<property
name=
"last_opened_file_path"
value=
"$PROJECT_DIR$"
/>
</component>
<component
name=
"RecentsManager"
>
<key
name=
"MoveFile.RECENT_KEYS"
>
<recent
name=
"D:\opcua-cloning"
/>
</key>
</component>
<component
name=
"RunManager"
selected=
"Python.opcua-client"
>
<configuration
name=
"main"
type=
"PythonConfigurationType"
factoryName=
"Python"
nameIsGenerated=
"true"
>
<module
name=
"opcua-cloning"
/>
<option
name=
"INTERPRETER_OPTIONS"
value=
""
/>
...
...
@@ -22,5 +47,42 @@
<option
name=
"INPUT_FILE"
value=
""
/>
<method
v=
"2"
/>
</configuration>
<configuration
name=
"opcua-client"
type=
"PythonConfigurationType"
factoryName=
"Python"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"opcua-cloning"
/>
<option
name=
"INTERPRETER_OPTIONS"
value=
""
/>
<option
name=
"PARENT_ENVS"
value=
"true"
/>
<envs>
<env
name=
"PYTHONUNBUFFERED"
value=
"1"
/>
</envs>
<option
name=
"SDK_HOME"
value=
""
/>
<option
name=
"WORKING_DIRECTORY"
value=
"$PROJECT_DIR$"
/>
<option
name=
"IS_MODULE_SDK"
value=
"true"
/>
<option
name=
"ADD_CONTENT_ROOTS"
value=
"true"
/>
<option
name=
"ADD_SOURCE_ROOTS"
value=
"true"
/>
<option
name=
"SCRIPT_NAME"
value=
"$PROJECT_DIR$/opcua-client.py"
/>
<option
name=
"PARAMETERS"
value=
""
/>
<option
name=
"SHOW_COMMAND_LINE"
value=
"false"
/>
<option
name=
"EMULATE_TERMINAL"
value=
"false"
/>
<option
name=
"MODULE_MODE"
value=
"false"
/>
<option
name=
"REDIRECT_INPUT"
value=
"false"
/>
<option
name=
"INPUT_FILE"
value=
""
/>
<method
v=
"2"
/>
</configuration>
<recent_temporary>
<list>
<item
itemvalue=
"Python.opcua-client"
/>
</list>
</recent_temporary>
</component>
<component
name=
"SpellCheckerSettings"
RuntimeDictionaries=
"0"
Folders=
"0"
CustomDictionaries=
"0"
DefaultDictionary=
"application-level"
UseSingleDictionary=
"true"
transferred=
"true"
/>
<component
name=
"TaskManager"
>
<task
active=
"true"
id=
"Default"
summary=
"Default task"
>
<changelist
id=
"e733891a-c063-4f94-92d6-4559e921107b"
name=
"Default Changelist"
comment=
""
/>
<created>
1677231122232
</created>
<option
name=
"number"
value=
"Default"
/>
<option
name=
"presentableId"
value=
"Default"
/>
<updated>
1677231122232
</updated>
</task>
<servers
/>
</component>
</project>
\ No newline at end of file
opcua-client.py
View file @
49ee43c7
from
opcua
import
Client
import
asyncio
import
socket
url
=
"opc.tcp://klblrlp1437.corp.knowledgelens.com:53530/OPCUA/SimulationServer"
client
=
Client
(
url
)
client
.
connect
()
from
asyncua
import
Client
,
Node
from
asyncua.common.subscription
import
DataChangeNotif
,
SubHandler
root
=
client
.
get_root_node
()
objects
=
root
.
get_children
()
for
obj
in
objects
:
print
(
f
"Object: {obj.get_browse_name()}"
)
msgFromClient
=
"Hello UDP Server"
bytesToSend
=
str
.
encode
(
msgFromClient
)
serverAddressPort
=
(
"2.2.2.5"
,
20001
)
bufferSize
=
1024
UDPClientSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
nodes
=
obj
.
get_children
()
ENDPOINT
=
'opc.tcp://2.2.2.7:53530/OPCUA/SimulationServer'
NAMESPACE
=
'http://www.prosysopc.com/OPCUA/SimulationServer/'
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
:
# Get data in a queue.
[
node
,
value
,
data
]
=
self
.
_queue
.
get_nowait
()
path
=
await
node
.
get_path
(
as_string
=
True
)
datatype
=
type
(
value
)
packet
=
str
(
datatype
)
+
"&"
+
str
(
value
)
+
"&"
+
'ns='
+
str
(
node
.
nodeid
.
NamespaceIndex
)
+
";i="
+
str
(
node
.
nodeid
.
Identifier
)
UDPClientSocket
.
sendto
(
str
.
encode
(
packet
),
serverAddressPort
)
except
asyncio
.
QueueEmpty
:
pass
async
def
get_nodes
(
client
):
subnodes
=
None
root
=
client
.
get_root_node
()
objects
=
await
root
.
get_children
()
for
obj
in
objects
:
nodes
=
await
obj
.
get_children
()
for
node
in
nodes
:
node_id
=
node
.
nodeid
.
Identifier
identifier
=
node
.
get_browse_name
()
.
Name
if
(
node_id
==
str
(
'85/0:Simulation'
)):
object_node
=
client
.
get_node
(
node
)
subnodes
=
node
.
get_children
()
for
snode
in
subnodes
:
value
=
client
.
get_node
(
snode
)
.
get_value
()
print
(
value
)
client
.
disconnect
()
if
(
node_id
==
str
(
'85/0:Simulation'
)):
subnodes
=
await
node
.
get_children
()
return
subnodes
async
def
main
()
->
None
:
async
with
Client
(
url
=
ENDPOINT
)
as
client
:
# Get a variable node.
node
=
await
get_nodes
(
client
)
# Subscribe data change.
handler
=
MyHandler
()
subscription
=
await
client
.
create_subscription
(
period
=
0
,
handler
=
handler
)
await
subscription
.
subscribe_data_change
(
node
)
# Process data change every 100ms
while
True
:
await
handler
.
process
()
await
asyncio
.
sleep
(
0.1
)
if
__name__
==
'__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