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

update

parent 2121bfdd
......@@ -49,7 +49,7 @@
<recent name="D:\opcua-cloning" />
</key>
</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">
<module name="opcua-cloning" />
<option name="INTERPRETER_OPTIONS" value="" />
......@@ -178,8 +178,8 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.hash_sender" />
<item itemvalue="Python.opcua-transmitter (1)" />
<item itemvalue="Python.hash_sender" />
<item itemvalue="Python.opcua_receiver" />
<item itemvalue="Python.asyncua_server (1)" />
<item itemvalue="Python.asyncua_server" />
......
import asyncio
from asyncua import ua, Server
import random
import socket
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():
def __init__(self):
self.server=None
......@@ -39,8 +45,15 @@ class asyncua_server():
# stop the server
await self.server.stop()
asr = asyncua_server()
def hash_receive():
while (True):
bytesAddressPair = UDPServerSocket.recvfrom(bufferSize)
message = bytesAddressPair[0]
print(message)
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"))
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():
UDPClientSocket.sendto(hierarchy, serverAddressPort)
print(hierarchy)
if __name__ == '__main__':
def send_hash():
asyncio.run(get_send_hash())
\ No newline at end of file
import asyncio
import socket
import threading
import hash_sender
from asyncua import Client, Node
from asyncua.common.subscription import DataChangeNotif, SubHandler
......@@ -51,6 +52,8 @@ async def main() -> None:
# Get a variable node.
node = await get_nodes(client)
# Subscribe data change.
t1=threading.Thread(target=hash_sender.send_hash)
t1.start()
handler = MyHandler()
subscription = await client.create_subscription(period=0, handler=handler)
await subscription.subscribe_data_change(node)
......@@ -58,7 +61,7 @@ async def main() -> None:
# Process data change every 100ms
while True:
await handler.process()
await asyncio.sleep(0.1)
await asyncio.sleep(1)
if __name__ == '__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