Commit 05e93a91 authored by yogesh.m's avatar yogesh.m

update

parent 2121bfdd
...@@ -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" />
......
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"))
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
...@@ -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
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())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment