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
4f9cd8b4
Commit
4f9cd8b4
authored
Mar 07, 2023
by
yogesh.m
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
26e0a8d7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
49 deletions
+57
-49
asyncua_server.py
asyncua_server.py
+5
-3
opcua_receiver.py
opcua_receiver.py
+3
-3
opcua_subscriber/__pycache__/opcua_subscribe.cpython-39.pyc
opcua_subscriber/__pycache__/opcua_subscribe.cpython-39.pyc
+0
-0
opcua_subscriber/opcua_subscribe.py
opcua_subscriber/opcua_subscribe.py
+49
-43
No files found.
asyncua_server.py
View file @
4f9cd8b4
...
@@ -5,7 +5,7 @@ import socket
...
@@ -5,7 +5,7 @@ import socket
import
threading
import
threading
from
time
import
sleep
from
time
import
sleep
localIP
=
"2.2.2.
5
"
localIP
=
"2.2.2.
7
"
localPort
=
20002
localPort
=
20002
bufferSize
=
1024
bufferSize
=
1024
UDPServerSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
UDPServerSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
...
@@ -47,7 +47,9 @@ class asyncua_server():
...
@@ -47,7 +47,9 @@ class asyncua_server():
uri
=
uri
uri
=
uri
self
.
idx
=
await
self
.
server
.
register_namespace
(
uri
)
self
.
idx
=
await
self
.
server
.
register_namespace
(
uri
)
await
self
.
server
.
start
()
await
self
.
server
.
start
()
obj
=
self
.
server
.
nodes
.
objects
.
add_object
(
self
.
idx
,
"MyObject"
)
obj
=
await
self
.
server
.
nodes
.
objects
.
add_folder
(
self
.
idx
,
"myobj"
)
var
=
await
obj
.
add_variable
(
self
.
idx
,
"myvar"
,
0
)
await
var
.
set_writable
()
try
:
try
:
# keep the server running until interrupted
# keep the server running until interrupted
while
True
:
while
True
:
...
@@ -77,4 +79,4 @@ def hash_receive():
...
@@ -77,4 +79,4 @@ def hash_receive():
def
st
():
def
st
():
t1
=
threading
.
Thread
(
target
=
hash_receive
)
t1
=
threading
.
Thread
(
target
=
hash_receive
)
t1
.
start
()
t1
.
start
()
asyncio
.
run
(
asr
.
start_server
(
"opc.tcp://2.2.2.
5
:53531/myopc/free"
,
"http://klopc.com"
))
asyncio
.
run
(
asr
.
start_server
(
"opc.tcp://2.2.2.
7
:53531/myopc/free"
,
"http://klopc.com"
))
opcua_receiver.py
View file @
4f9cd8b4
...
@@ -5,7 +5,7 @@ from asyncua_server import st
...
@@ -5,7 +5,7 @@ from asyncua_server import st
import
asyncio
import
asyncio
import
threading
import
threading
localIP
=
"2.2.2.
5
"
localIP
=
"2.2.2.
7
"
localPort
=
20001
localPort
=
20001
...
@@ -26,10 +26,10 @@ UDPServerSocket.bind((localIP, localPort))
...
@@ -26,10 +26,10 @@ UDPServerSocket.bind((localIP, localPort))
print
(
"UDP server up and listening"
)
print
(
"UDP server up and listening"
)
t1
=
threading
.
Thread
(
target
=
st
,
args
=
())
t1
=
threading
.
Thread
(
target
=
st
,
args
=
())
t1
.
start
()
t1
.
start
()
sleep
(
1
0
)
sleep
(
1
)
print
(
"here"
)
print
(
"here"
)
opua
=
opcua_pack
()
opua
=
opcua_pack
()
sock
=
opua
.
connect
(
"opc.tcp://2.2.2.
5
:53531/myopc/free"
)
sock
=
opua
.
connect
(
"opc.tcp://2.2.2.
7
:53531/myopc/free"
)
while
(
True
):
while
(
True
):
bytesAddressPair
=
UDPServerSocket
.
recvfrom
(
bufferSize
)
bytesAddressPair
=
UDPServerSocket
.
recvfrom
(
bufferSize
)
...
...
opcua_subscriber/__pycache__/opcua_subscribe.cpython-39.pyc
View file @
4f9cd8b4
No preview for this file type
opcua_subscriber/opcua_subscribe.py
View file @
4f9cd8b4
...
@@ -141,7 +141,7 @@ class opcua_pack():
...
@@ -141,7 +141,7 @@ class opcua_pack():
DiscoveryProfileUri
=
binascii
.
unhexlify
(
"ffffffff"
)
DiscoveryProfileUri
=
binascii
.
unhexlify
(
"ffffffff"
)
ArraySize
=
0
ArraySize
=
0
ServerUri
=
binascii
.
unhexlify
(
"ffffffff"
)
ServerUri
=
binascii
.
unhexlify
(
"ffffffff"
)
EndpointUrl
=
"opc.tcp://2.2.2.
5
:53531/myopc/free"
EndpointUrl
=
"opc.tcp://2.2.2.
7
:53531/myopc/free"
EndpointUrllen
=
len
(
EndpointUrl
.
encode
())
.
to_bytes
(
4
,
byteorder
=
"little"
)
EndpointUrllen
=
len
(
EndpointUrl
.
encode
())
.
to_bytes
(
4
,
byteorder
=
"little"
)
SessionName
=
"Pure Python Client Session1"
SessionName
=
"Pure Python Client Session1"
SessionNamelen
=
len
(
SessionName
.
encode
())
.
to_bytes
(
4
,
byteorder
=
"little"
)
SessionNamelen
=
len
(
SessionName
.
encode
())
.
to_bytes
(
4
,
byteorder
=
"little"
)
...
@@ -151,48 +151,53 @@ class opcua_pack():
...
@@ -151,48 +151,53 @@ class opcua_pack():
RequestedSessionTimeout
=
binascii
.
unhexlify
(
"0000000040774B41"
)
RequestedSessionTimeout
=
binascii
.
unhexlify
(
"0000000040774B41"
)
MaxResponseMessageSize
=
0
MaxResponseMessageSize
=
0
Message_body
=
SecureChannelId
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
Security_Token_Id
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
Security_Sequence_Number
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
Security_RequestId
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
NodeId_EncodingMask
.
to_bytes
(
1
,
byteorder
=
'little'
)
+
\
NodeId_Namespace_Index
.
to_bytes
(
1
,
byteorder
=
'little'
)
+
\
NodeId_Identifier_Numeric
.
to_bytes
(
2
,
byteorder
=
'little'
)
+
\
auth_EncodingMask
.
to_bytes
(
1
,
byteorder
=
'little'
)
+
\
Identifier_Numeric
.
to_bytes
(
1
,
byteorder
=
'little'
)
+
\
Timestamp
+
\
RequestHandle
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
Return_Diagnostics
+
\
AuditEntryId
+
\
TimeoutHint
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
additional_header_enc_mask
+
\
ah_Identifier_Numeric
.
to_bytes
(
1
,
byteorder
=
"little"
)
+
\
ah_EncodingMask2
+
\
ApplicationUrilen
+
\
ApplicationUri
.
encode
()
+
\
ProductUrilen
+
\
ProductUri
.
encode
()
+
\
Application_name
+
\
Textlen
+
\
Text
.
encode
()
+
\
ApplicationType
+
\
GatewayServerUri
+
\
DiscoveryProfileUri
+
\
ArraySize
.
to_bytes
(
4
,
byteorder
=
"little"
)
+
\
ServerUri
+
\
EndpointUrllen
+
\
EndpointUrl
.
encode
()
+
\
SessionNamelen
+
\
SessionName
.
encode
()
+
\
client_noncelen
+
\
client_nonce
+
\
ClientCertificate
+
\
RequestedSessionTimeout
+
\
MaxResponseMessageSize
.
to_bytes
(
4
,
byteorder
=
"little"
)
Message_Size
=
int
(
8
+
len
(
Message_body
))
.
to_bytes
(
4
,
byteorder
=
"little"
)
session
=
MSG_MSG
.
encode
()
+
\
session
=
MSG_MSG
.
encode
()
+
\
chunk_type
.
encode
()
+
\
chunk_type
.
encode
()
+
\
Message_Size
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
Message_Size
+
\
SecureChannelId
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
Message_body
Security_Token_Id
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
Security_Sequence_Number
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
Security_RequestId
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
NodeId_EncodingMask
.
to_bytes
(
1
,
byteorder
=
'little'
)
+
\
NodeId_Namespace_Index
.
to_bytes
(
1
,
byteorder
=
'little'
)
+
\
NodeId_Identifier_Numeric
.
to_bytes
(
2
,
byteorder
=
'little'
)
+
\
auth_EncodingMask
.
to_bytes
(
1
,
byteorder
=
'little'
)
+
\
Identifier_Numeric
.
to_bytes
(
1
,
byteorder
=
'little'
)
+
\
Timestamp
+
\
RequestHandle
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
Return_Diagnostics
+
\
AuditEntryId
+
\
TimeoutHint
.
to_bytes
(
4
,
byteorder
=
'little'
)
+
\
additional_header_enc_mask
+
\
ah_Identifier_Numeric
.
to_bytes
(
1
,
byteorder
=
"little"
)
+
\
ah_EncodingMask2
+
\
ApplicationUrilen
+
\
ApplicationUri
.
encode
()
+
\
ProductUrilen
+
\
ProductUri
.
encode
()
+
\
Application_name
+
\
Textlen
+
\
Text
.
encode
()
+
\
ApplicationType
+
\
GatewayServerUri
+
\
DiscoveryProfileUri
+
\
ArraySize
.
to_bytes
(
4
,
byteorder
=
"little"
)
+
\
ServerUri
+
\
EndpointUrllen
+
\
EndpointUrl
.
encode
()
+
\
SessionNamelen
+
\
SessionName
.
encode
()
+
\
client_noncelen
+
\
client_nonce
+
\
ClientCertificate
+
\
RequestedSessionTimeout
+
\
MaxResponseMessageSize
.
to_bytes
(
4
,
byteorder
=
"little"
)
return
session
return
session
def
start_session
(
self
,
secure_id
,
token_id
,
identifier_string
):
def
start_session
(
self
,
secure_id
,
token_id
,
identifier_string
):
MSG_MSG
=
"MSG"
MSG_MSG
=
"MSG"
chunk_type
=
"F"
chunk_type
=
"F"
...
@@ -421,7 +426,7 @@ class opcua_pack():
...
@@ -421,7 +426,7 @@ class opcua_pack():
return
session
return
session
def
connect
(
self
,
address
):
def
connect
(
self
,
address
):
server_address
=
(
'2.2.2.
5
'
,
53531
)
server_address
=
(
'2.2.2.
7
'
,
53531
)
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
.
connect
(
server_address
)
sock
.
connect
(
server_address
)
message
=
self
.
helf
(
address
)
message
=
self
.
helf
(
address
)
...
@@ -431,7 +436,8 @@ class opcua_pack():
...
@@ -431,7 +436,8 @@ class opcua_pack():
data
=
sock
.
recv
(
10249
)
data
=
sock
.
recv
(
10249
)
self
.
SecureChannelId
=
int
(
data
[
-
24
:
-
23
]
.
hex
(),
16
)
self
.
SecureChannelId
=
int
(
data
[
-
24
:
-
23
]
.
hex
(),
16
)
self
.
TokenId
=
int
(
data
[
-
20
:
-
19
]
.
hex
(),
16
)
self
.
TokenId
=
int
(
data
[
-
20
:
-
19
]
.
hex
(),
16
)
sock
.
sendall
(
self
.
create_session
(
self
.
SecureChannelId
,
self
.
TokenId
))
message
=
self
.
create_session
(
self
.
SecureChannelId
,
self
.
TokenId
)
sock
.
sendall
(
message
)
count
=
0
count
=
0
while
True
:
while
True
:
try
:
try
:
...
...
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