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 USBDAQF1AD.
 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-2025 WPC Systems Ltd. All rights reserved.
18'''
19
20## WPC
21from wpcsys import pywpc
22
23## Python
24import time
25
26
27def main():
28    ## Get Python driver version
29    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
30
31    ## Create device handle
32    dev = pywpc.USBDAQF1AD()
33
34    ## Connect to device
35    try:
36        dev.connect("default")  ## Depend on your device
37    except Exception as err:
38        pywpc.printGenericError(err)
39        ## Release device handle
40        dev.close()
41        return
42
43    try:
44        ## Parameters setting
45        port = 0  ## Depend on your device
46        timeout = 3  ## [sec]
47
48        ## Get firmware model & version
49        driver_info = dev.Sys_getDriverInfo(timeout)
50        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
51
52        ## Open port with digital output
53        err = dev.DO_openPort(port, timeout)
54        print(f"DO_openPort in port {port}, status: {err}")
55
56        ## Toggle digital state for 10 times. Each times delay for 0.5 second
57        for i in range(10):
58            state = dev.DO_togglePort(port, timeout)
59            print(state)
60
61            ## Wait for 0.5 second to see led status
62            time.sleep(0.5)  ## delay [sec]
63
64        ## Close port with digital output
65        err = dev.DO_closePort(port, timeout)
66        print(f"DO_closePort in port {port}, status: {err}")
67    except Exception as err:
68        pywpc.printGenericError(err)
69
70    finally:
71        ## Disconnect device
72        dev.disconnect()
73
74        ## Release device handle
75        dev.close()
76
77
78if __name__ == '__main__':
79    main()