DO blinky port

 1'''
 2DIO - DO_blinky_port.py with synchronous mode.
 3
 4This example illustrates the process of writing a high or low signal to a DO port from WifiDAQE3AOD.
 5
 6To begin with, it demonstrates the steps required to open the DO port.
 7Next, in each loop, a different voltage output is applied, resulting in a blinking effect.
 8Lastly, it concludes by closing the DO port.
 9
10-------------------------------------------------------------------------------------
11Please change correct serial number or IP and port number BEFORE you run example code.
12
13For other examples please check:
14    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
15See README.md file to get detailed usage of this example.
16
17Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
18'''
19
20## Python
21import time
22
23## WPC
24
25from wpcsys import pywpc
26
27
28def main():
29    ## Get Python driver version
30    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
31
32    ## Create device handle
33    dev = pywpc.WifiDAQE3AOD()
34
35    ## Connect to device
36    try:
37        dev.connect("192.168.5.38") ## Depend on your device
38    except Exception as err:
39        pywpc.printGenericError(err)
40        ## Release device handle
41        dev.close()
42        return
43
44    try:
45        ## Parameters setting
46        port = 2  ## Depend on your device
47        timeout = 3 ## second
48
49        ## Get firmware model & version
50        driver_info = dev.Sys_getDriverInfo(timeout)
51        print("Model name: " + driver_info[0])
52        print("Firmware version: " + driver_info[-1])
53
54        ## Open port with digital output
55        err = dev.DO_openPort(port, timeout)
56        print(f"DO_openPort in port {port}, status: {err}")
57
58        ## Toggle digital state for 10 times. Each times delay for 0.5 second
59        for i in range(10):
60            state = dev.DO_togglePort(port, timeout)
61            print(state)
62
63            ## Wait for 0.5 second to see led status
64            time.sleep(0.5) ## delay [s]
65
66        ## Close port with digital output
67        err = dev.DO_closePort(port, timeout)
68        print(f"DO_closePort in port {port}, status: {err}")
69    except Exception as err:
70        pywpc.printGenericError(err)
71
72    ## Disconnect device
73    dev.disconnect()
74
75    ## Release device handle
76    dev.close()
77
78    return
79
80if __name__ == '__main__':
81    main()