1'''
2System_ETH - hello_world.py with asynchronous mode.
3
4This example code is in the public domain from EthanT.
5
6-------------------------------------------------------------------------------------
7Please change correct serial number or IP and port number BEFORE you run example code.
8
9For other examples please check:
10 https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
11See README.md file to get detailed usage of this example.
12
13Copyright (c) 2022-2025 WPC Systems Ltd. All rights reserved.
14'''
15
16## WPC
17from wpcsys import pywpc
18
19## Python
20import asyncio
21import sys
22sys.path.insert(0, 'src/')
23
24
25async def main():
26 ## Get Python driver version
27 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
28
29 ## Create device handle
30 dev = pywpc.EthanT()
31
32 ## Connect to device
33 try:
34 dev.connect("192.168.1.110") ## Depend on your device
35 except Exception as err:
36 pywpc.printGenericError(err)
37 ## Release device handle
38 dev.close()
39 return
40
41 try:
42 for i in range(10, 0, -1):
43 print(f"Restarting in {i} seconds...")
44 await asyncio.sleep(1) ## delay [sec]
45
46 print("Restarting now")
47 await dev.Sys_reboot_async()
48 except Exception as err:
49 pywpc.printGenericError(err)
50
51 finally:
52 ## Disconnect network device
53 dev.disconnect()
54
55 ## Release device handle
56 dev.close()
57
58
59def main_for_spyder(*args):
60 if asyncio.get_event_loop().is_running():
61 return asyncio.create_task(main(*args)).result()
62 else:
63 return asyncio.run(main(*args))
64
65
66if __name__ == '__main__':
67 asyncio.run(main()) ## Use terminal
68 # await main() ## Use Jupyter or IPython(>=7.0)
69 # main_for_spyder() ## Use Spyder