System get pin mode

 1'''
 2System_USB - get_pin_mode.py with asynchronous mode.
 3
 4This example demonstrates how to get pin mode from USBDAQF1D.
 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 asyncio
22
23## WPC
24
25from wpcsys import pywpc
26
27async def main():
28    ## Get Python driver version
29    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
30
31    ## Create device handle
32    dev = pywpc.USBDAQF1D()
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        ## Get firmware model & version
45        driver_info = await dev.Sys_getDriverInfo_async()
46        print("Firmware model:" + driver_info[0])
47        print("Firmware version:" + driver_info[-1])
48
49        ## Get pinmode from port 0 to port 3
50        for i in range(4):
51            ## Get pin mode
52            pin_mode = await dev.Sys_getPinModeInPort_async(i)
53            print("pin_mode", pin_mode)
54    except Exception as err:
55        pywpc.printGenericError(err)
56
57    ## Disconnect device
58    dev.disconnect()
59
60    ## Release device handle
61    dev.close()
62
63    return
64
65def main_for_spyder(*args):
66    if asyncio.get_event_loop().is_running():
67        return asyncio.create_task(main(*args)).result()
68    else:
69        return asyncio.run(main(*args))
70
71if __name__ == '__main__':
72    asyncio.run(main()) ## Use terminal
73    # await main() ## Use Jupyter or IPython(>=7.0)
74    # main_for_spyder() ## Use Spyder