1
2'''
3SNTP - SNTP configure.py with synchronous mode.
4
5This example demonstrates how to configure SNTP from EthanA2.
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
25def main():
26 ## Get Python driver version
27 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
28
29 ## Create device handle
30 dev = pywpc.EthanA2()
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 timeout = 3 ## second
46
47 ## Get firmware model & version
48 driver_info = dev.Sys_getDriverInfo(timeout)
49 print("Model name: " + driver_info[0])
50 print("Firmware version: " + driver_info[-1])
51
52 ## Set SNTP server IP
53 err = dev.SNTP_setServerIP(ip_addr, timeout)
54 print(f"SNTP_setServerIP, status: {err}")
55
56 ## Set SNTP period
57 err = dev.SNTP_setPeriod(period, timeout)
58 print(f"SNTP_setPeriod, status: {err}")
59
60 ## Sync now
61 err = dev.SNTP_syncNow(timeout)
62 print(f"SNTP_syncNow, status: {err}")
63 except Exception as err:
64 pywpc.printGenericError(err)
65
66 ## Disconnect device
67 dev.disconnect()
68
69 ## Release device handle
70 dev.close()
71
72 return
73if __name__ == '__main__':
74 main()