1'''
2DIO - DO_blinky_pins.py with synchronous mode.
3
4This example illustrates the process of writing a high or low signal to a DO pin from USBDAQF1TD.
5
6To begin with, it demonstrates the steps required to open the DO pin.
7Next, in each loop, a different voltage output is applied, resulting in a blinking effect.
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.USBDAQF1TD()
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 pinindex = [1, 3, 5, 7]
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 pins with digital output
54 err = dev.DO_openPins(port, pinindex, timeout)
55 print(f"DO_openPins in port {port}, status: {err}")
56
57 ## Toggle digital state for 10 times. Each times delay for 0.5 second
58 for i in range(10):
59 state = dev.DO_togglePins(port, pinindex, timeout)
60 print(state)
61
62 ## Wait for 0.5 second to see led status
63 time.sleep(0.5) ## delay [sec]
64
65 ## Close pins with digital output
66 err = dev.DO_closePins(port, pinindex, 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()