1'''
2DIO - DO_write_port.py with synchronous mode.
3
4This example illustrates the process of writing a high or low signal to a DO port from USBDAQF1AOD.
5
6To begin with, it demonstrates the steps required to open the DO port.
7Next, voltage output is written to the DO port.
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.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 DO_value = [1, 0, 1, 0]
47 timeout = 3 ## [sec]
48
49 ## Get firmware model & version
50 driver_info = dev.Sys_getDriverInfo(timeout)
51 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
52
53 ## Open port to digital output
54 err = dev.DO_openPort(port, timeout)
55 print(f"DO_openPort in port {port}, status: {err}")
56
57 ## Write port to high or low
58 err = dev.DO_writePort(port, DO_value, timeout)
59 print(f"DO_writePort in port {port}, status: {err}")
60
61 ## Wait for seconds to see led status
62 time.sleep(3) ## 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()