Commit 2200d746 authored by yogesh.m's avatar yogesh.m

update

parent 735a8260
import asyncio
from asyncua import ua, Server
import random
import threading
class asyncua_server():
def __init__(self):
......@@ -8,6 +9,7 @@ class asyncua_server():
self.idx=None
async def add_object(self,obj):
print(self.idx,obj)
return await self.server.nodes.objects.add_object(self.idx,obj )
async def add_variable(self,obj,var):
......@@ -16,6 +18,7 @@ class asyncua_server():
return var
async def start_server(self,url,uri):
print(url)
# create a server
self.server = Server()
await self.server.init()
......@@ -25,20 +28,19 @@ class asyncua_server():
# create a new address space
uri = 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()
obj = self.server.nodes.objects.add_object(self.idx, "MyObject")
try:
# keep the server running until interrupted
while True:
#await var.write_value(random.randint(1, 100))
await asyncio.sleep(1)
#var.write_value(random.randint(1, 100))
await asyncio.sleep(0.1)
finally:
# stop the server
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"))
import socket
from opcua import Client,ua
from opcua_subscriber.opcua_subscribe import *
from asyncua_server import asyncua_server
# client = Client("opc.tcp:2.2.2.7:53530/OPCUA/SimulationServer")
# client.connect()
from asyncua_server import st
import asyncio
import threading
localIP = "2.2.2.5"
......@@ -22,16 +21,15 @@ UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
# Bind to address and ip
UDPServerSocket.bind((localIP, localPort))
#UDPServerSocket.bind((localIP, localPort))
print("UDP server up and listening")
t1=threading.Thread(target=st,args=())
t1.start()
print("here")
opua=opcua_pack()
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):
bytesAddressPair = UDPServerSocket.recvfrom(bufferSize)
message = bytesAddressPair[0]
......
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