1'''
2System_USB - get_pin_mode.py with synchronous mode.
3
4This example demonstrates how to get pin mode from USBDAQF1TD.
5
6First, get idle pin mode and show how to open DO and DI in pins.
7Second, get idle pin mode and set port idle mode. Again, get pin mode.
8Last, close DO and DI in 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-2024 WPC Systems Ltd. All rights reserved.
18'''
19
20## Python
21import time
22
23## WPC
24
25from wpcsys import pywpc
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 = None ## Depend on your device
46 timeout = 3 ## second
47
48 ## Get firmware model & version
49 driver_info = dev.Sys_getDriverInfo(timeout)
50 print("Firmware model:" + driver_info[0])
51 print("Firmware version:" + driver_info[-1])
52
53 ## Get pinmode from port 0 to port 3
54 for i in range(4):
55 ## Get pin mode
56 pin_mode = dev.Sys_getPinModeInPort(i, timeout)
57 print("pin_mode", pin_mode)
58 except Exception as err:
59 pywpc.printGenericError(err)
60
61 ## Disconnect device
62 dev.disconnect()
63
64 ## Release device handle
65 dev.close()
66
67 return
68
69if __name__ == '__main__':
70 main()