1
2'''
3SNTP - SNTP configure.py with asynchronous mode.
4
5This example demonstrates how to configure SNTP from EthanA.
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-2024 WPC Systems Ltd. All rights reserved.
15'''
16
17## Python
18import asyncio
19
20## WPC
21
22from wpcsys import pywpc
23import time
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.EthanA()
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 ## Parameters setting
43 ip_addr = "255.255.255.255" ## Automatic search
44 period = 5 ## second
45
46 ## Get firmware model & version
47 driver_info = await dev.Sys_getDriverInfo_async()
48 print("Model name: " + driver_info[0])
49 print("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 ## Disconnect device
66 dev.disconnect()
67
68 ## Release device handle
69 dev.close()
70
71 return
72def main_for_spyder(*args):
73 if asyncio.get_event_loop().is_running():
74 return asyncio.create_task(main(*args)).result()
75 else:
76 return asyncio.run(main(*args))
77if __name__ == '__main__':
78 asyncio.run(main()) ## Use terminal
79 # await main() ## Use Jupyter or IPython(>=7.0)
80 # main_for_spyder() ## Use Spyder