DO write pins

 1'''
 2DIO - DO_write_pins.py with synchronous mode.
 3
 4This example illustrates the process of writing a high or low signal to a DO pin from USBDAQF1AOD.
 5
 6To begin with, it demonstrates the steps required to open the DO pin.
 7Next, voltage output is written to the DO pin.
 8Lastly, it concludes by closing the DO pin.
 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.USBDAQF1AOD()
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        pin_index = [0, 1, 2, 3]
47        DO_value = [1, 0, 1, 0]
48        timeout = 3  ## [sec]
49
50        ## Get firmware model & version
51        driver_info = dev.Sys_getDriverInfo(timeout)
52        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
53
54        ## Open pins with digital output
55        err = dev.DO_openPins(port, pin_index, timeout)
56        print(f"DO_openPins in port {port}, status: {err}")
57
58        ## Write pins to high or low
59        err = dev.DO_writePins(port, pin_index, DO_value, timeout)
60        print(f"DO_writePins in port {port}, status: {err}")
61
62        ## Wait for seconds to see led status
63        time.sleep(3)  ## delay [sec]
64
65        ## Close pins with digital output
66        err = dev.DO_closePins(port, pin_index, timeout)
67        print(f"DO_closePins in port {port}, status: {err}")
68    except Exception as err:
69        pywpc.printGenericError(err)
70
71    finally:
72        ## Disconnect device
73        dev.disconnect()
74
75        ## Release device handle
76        dev.close()
77
78
79if __name__ == '__main__':
80    main()