Set and get RTC

 1'''
 2System_USB - set_and_get_RTC.py with synchronous mode.
 3
 4This example demonstrates how to set and get RTC from USBDAQF1TD.
 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-2024 WPC Systems Ltd. All rights reserved.
14'''
15
16## Python
17import time
18
19## WPC
20
21from wpcsys import pywpc
22
23def main():
24    ## Get Python driver version
25    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
26
27    ## Create device handle
28    dev = pywpc.USBDAQF1TD()
29
30    ## Connect to device
31    try:
32        dev.connect("default") ## Depend on your device
33    except Exception as err:
34        pywpc.printGenericError(err)
35        ## Release device handle
36        dev.close()
37        return
38
39    try:
40        ## Parameters setting
41        delay = 1 ## second
42        timeout = 3 ## second
43
44        ## Get firmware model & version
45        driver_info = dev.Sys_getDriverInfo(timeout)
46        print("Model name: " + driver_info[0])
47        print("Firmware version: " + driver_info[-1])
48
49        ## Set RTC
50        err = dev.Sys_setRTC(2023, 5, 8, 15, 8, 7, timeout)
51        print(f"Set RTC to 2023-05-08, 15:08:07 , status: {err}")
52
53        for i in range(10):
54            ## Get RTC
55            print(f"Get RTC: {dev.Sys_getRTC()}")
56            time.sleep(delay) ## delay [s]
57
58    except Exception as err:
59        pywpc.printGenericError(err)
60
61    ## Disconnect network device
62    dev.disconnect()
63
64    ## Release device handle
65    dev.close()
66
67    return
68
69if __name__ == '__main__':
70    main()