1
2'''
3SNTP - SNTP configure.py with asynchronous mode.
4
5This example demonstrates how to configure SNTP from EthanD.
6
7-------------------------------------------------------------------------------------
8Please change correct serial number or IP and port number BEFORE you run example code.
9
10For other examples please check:
11 https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
12See README.md file to get detailed usage of this example.
13
14Copyright (c) 2022-2025 WPC Systems Ltd. All rights reserved.
15'''
16
17## WPC
18from wpcsys import pywpc
19
20## Python
21import asyncio
22import sys
23sys.path.insert(0, 'src/')
24
25
26async def main():
27 ## Get Python driver version
28 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
29
30 ## Create device handle
31 dev = pywpc.EthanD()
32
33 ## Connect to device
34 try:
35 dev.connect("192.168.1.110") ## Depend on your device
36 except Exception as err:
37 pywpc.printGenericError(err)
38 ## Release device handle
39 dev.close()
40 return
41
42 try:
43 ## Parameters setting
44 ip_addr = "255.255.255.255" ## Automatic search
45 period = 5 ## [sec]
46
47 ## Get firmware model & version
48 driver_info = await dev.Sys_getDriverInfo_async()
49 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
50
51 ## Set SNTP server IP
52 err = await dev.SNTP_setServerIP_async(ip_addr)
53 print(f"SNTP_setServerIP_async, status: {err}")
54
55 ## Set SNTP period
56 err = await dev.SNTP_setPeriod_async(period)
57 print(f"SNTP_setPeriod_async, status: {err}")
58
59 ## Sync now
60 err = await dev.SNTP_syncNow_async()
61 print(f"SNTP_syncNow_async, status: {err}")
62 except Exception as err:
63 pywpc.printGenericError(err)
64
65 finally:
66 ## Disconnect device
67 dev.disconnect()
68
69 ## Release device handle
70 dev.close()
71
72
73def main_for_spyder(*args):
74 if asyncio.get_event_loop().is_running():
75 return asyncio.create_task(main(*args)).result()
76 else:
77 return asyncio.run(main(*args))
78
79
80if __name__ == '__main__':
81 asyncio.run(main()) ## Use terminal
82 # await main() ## Use Jupyter or IPython(>=7.0)
83 # main_for_spyder() ## Use Spyder