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 WifiDAQE3AOD.
 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-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        pin_index = [0, 1, 2, 3]
48        DO_value = [1, 0, 1, 0]
49        timeout = 3 ## second
50
51        ## Get firmware model & version
52        driver_info = dev.Sys_getDriverInfo(timeout)
53        print("Model name: " + driver_info[0])
54        print("Firmware version: " + driver_info[-1])
55
56        ## Open pins with digital output
57        err = dev.DO_openPins(port, pin_index, timeout)
58        print(f"DO_openPins in port {port}, status: {err}")
59
60        ## Write pins to high or low
61        err = dev.DO_writePins(port, pin_index, DO_value, timeout)
62        print(f"DO_writePins in port {port}, status: {err}")
63
64        ## Wait for seconds to see led status
65        time.sleep(3) ## delay [s]
66
67        ## Close pins with digital output
68        err = dev.DO_closePins(port, pin_index, timeout)
69        print(f"DO_closePins in port {port}, status: {err}")
70    except Exception as err:
71        pywpc.printGenericError(err)
72
73    ## Disconnect device
74    dev.disconnect()
75
76    ## Release device handle
77    dev.close()
78
79    return
80
81if __name__ == '__main__':
82    main()