Skip to content

Commit

Permalink
linting of server-callback example
Browse files Browse the repository at this point in the history
  • Loading branch information
oroulet committed Mar 9, 2021
1 parent d5c7acb commit ffaf440
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions examples/server-callback.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import sys
sys.path.insert(0, "..")
import logging
from datetime import datetime
import asyncio

try:
Expand All @@ -16,47 +13,46 @@ def embed():
shell.interact()


from asyncua import ua, uamethod, Server
from asyncua import ua, Server
from asyncua.common.callback import CallbackType



def create_monitored_items(event, dispatcher):
print("Monitored Item")
print("Monitored Item")

for idx in range(len(event.response_params)) :
if (event.response_params[idx].StatusCode.is_good()) :
for idx in range(len(event.response_params)):
if event.response_params[idx].StatusCode.is_good():
nodeId = event.request_params.ItemsToCreate[idx].ItemToMonitor.NodeId
print(f"Node {nodeId} was created")


def modify_monitored_items(event, dispatcher):
print('modify_monitored_items')
print("modify_monitored_items")


def delete_monitored_items(event, dispatcher):
print('delete_monitored_items')
print("delete_monitored_items")


async def main():
# optional: setup logging
logging.basicConfig(level=logging.WARN)
#logger = logging.getLogger("asyncua.address_space")
# logger = logging.getLogger("asyncua.address_space")
# logger.setLevel(logging.DEBUG)
#logger = logging.getLogger("asyncua.internal_server")
# logger = logging.getLogger("asyncua.internal_server")
# logger.setLevel(logging.DEBUG)
#logger = logging.getLogger("asyncua.binary_server_asyncio")
# logger = logging.getLogger("asyncua.binary_server_asyncio")
# logger.setLevel(logging.DEBUG)
#logger = logging.getLogger("asyncua.uaprocessor")
# logger = logging.getLogger("asyncua.uaprocessor")
# logger.setLevel(logging.DEBUG)
logger = logging.getLogger("asyncua.subscription_service")
logger.setLevel(logging.DEBUG)

# now setup our server
server = Server()
await server.init()
#await server.disable_clock()
#server.set_endpoint("opc.tcp://localhost:4840/freeopcua/server/")
# await server.disable_clock()
# server.set_endpoint("opc.tcp://localhost:4840/freeopcua/server/")
server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
server.set_server_name("FreeOpcUa Example Server")

Expand All @@ -71,20 +67,19 @@ async def main():
myfolder = await objects.add_folder(idx, "myEmptyFolder")
myobj = await objects.add_object(idx, "MyObject")
myvar = await myobj.add_variable(idx, "MyVariable", 6.7)
await myvar.set_writable() # Set MyVariable to be writable by clients

await myvar.set_writable() # Set MyVariable to be writable by clients

# starting!
await server.start()
# Create Callback for item event

# Create Callback for item event
server.subscribe_server_callback(CallbackType.ItemSubscriptionCreated, create_monitored_items)
server.subscribe_server_callback(CallbackType.ItemSubscriptionModified, modify_monitored_items)
server.subscribe_server_callback(CallbackType.ItemSubscriptionDeleted, delete_monitored_items)

while True:
await asyncio.sleep(1)


if __name__ == '__main__':
if __name__ == "__main__":
asyncio.run(main())

0 comments on commit ffaf440

Please sign in to comment.