Commit 735a8260 authored by yogesh.m's avatar yogesh.m

update

parent df04e11d
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
<recent name="D:\opcua-cloning" /> <recent name="D:\opcua-cloning" />
</key> </key>
</component> </component>
<component name="RunManager" selected="Python.opcua-transmitter (1)"> <component name="RunManager" selected="Python.asyncua_server (1)">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" 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="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
<option name="IS_MODULE_SDK" value="true" /> <option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/asyncua_server.py" />
<option name="PARAMETERS" value="" /> <option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="opcua-transmitter (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="asyncua_server" 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="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
<option name="IS_MODULE_SDK" value="true" /> <option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/opcua-transmitter.py" /> <option name="SCRIPT_NAME" value="D:\opcua-cloning\asyncua_server.py" />
<option name="PARAMETERS" value="" /> <option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="opcua-transmitter" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="opcua-cloning" /> <module name="opcua-cloning" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
...@@ -96,7 +96,28 @@ ...@@ -96,7 +96,28 @@
<option name="IS_MODULE_SDK" value="true" /> <option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="D:\opcua-cloning\opcua-transmitter.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.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>
<configuration name="opcua-transmitter (1)" 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-transmitter.py" />
<option name="PARAMETERS" value="" /> <option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
...@@ -149,10 +170,11 @@ ...@@ -149,10 +170,11 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Python.asyncua_server (1)" />
<item itemvalue="Python.asyncua_server" />
<item itemvalue="Python.opcua-transmitter (1)" /> <item itemvalue="Python.opcua-transmitter (1)" />
<item itemvalue="Python.opcua_receiver" /> <item itemvalue="Python.opcua_receiver" />
<item itemvalue="Python.test" /> <item itemvalue="Python.test" />
<item itemvalue="Python.opcua-transmitter" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
......
import asyncio
from asyncua import ua, Server
import random
async def main():
# create a server
server = Server()
await server.init()
# set endpoint information
url = "opc.tcp://localhost:4840/myopc/free"
server.set_endpoint(url)
# create a new address space
uri = "http://klopc.com"
idx = await server.register_namespace(uri)
obj = await server.nodes.objects.add_object(idx, "MyObject")
var = await obj.add_variable(idx, "MyVariable", 0)
await var.set_writable()
# start the server
await server.start()
try:
# keep the server running until interrupted
while True:
await var.write_value(random.randint(1, 100))
await asyncio.sleep(1)
finally:
# stop the server
await server.stop()
if __name__ == "__main__":
asyncio.run(main())
import asyncio
from asyncua import ua, Server
import random
class asyncua_server():
def __init__(self):
self.server=None
self.idx=None
async def add_object(self,obj):
return await self.server.nodes.objects.add_object(self.idx,obj )
async def add_variable(self,obj,var):
var= await obj.add_variable(self.idx,var, 11)
await var.set_writable()
return var
async def start_server(self,url,uri):
# create a server
self.server = Server()
await self.server.init()
# set endpoint information
url = url
self.server.set_endpoint(url)
# 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()
try:
# keep the server running until interrupted
while True:
#await var.write_value(random.randint(1, 100))
await asyncio.sleep(1)
finally:
# stop the server
await self.server.stop()
if __name__ == "__main__":
asua=asyncua_server()
asyncio.run(asua.start_server())
import socket import socket
from opcua import Client,ua from opcua import Client,ua
from opcua_subscriber.opcua_subscribe import * from opcua_subscriber.opcua_subscribe import *
from asyncua_server import asyncua_server
# client = Client("opc.tcp:2.2.2.7:53530/OPCUA/SimulationServer") # client = Client("opc.tcp:2.2.2.7:53530/OPCUA/SimulationServer")
# client.connect() # client.connect()
...@@ -27,6 +28,10 @@ print("UDP server up and listening") ...@@ -27,6 +28,10 @@ print("UDP server up and listening")
opua=opcua_pack() opua=opcua_pack()
sock = opua.connect("opc.tcp://2.2.2.5:53530/OPCUA/SimulationServer") 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): while (True):
bytesAddressPair = UDPServerSocket.recvfrom(bufferSize) bytesAddressPair = UDPServerSocket.recvfrom(bufferSize)
message = bytesAddressPair[0] 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