DPOT write all channels

 1'''
 2DPOT - DPOT_writeAllChannels.py with asynchronous mode.
 3
 4This example demonstrates how to write digital potentiometer resistance to all channel from EthanP.
 5-------------------------------------------------------------------------------------
 6Please change correct serial number or IP and port number BEFORE you run example code.
 7
 8For other examples please check:
 9    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
10See README.md file to get detailed usage of this example.
11
12Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
13'''
14
15## Python
16import asyncio
17
18## WPC
19
20from wpcsys import pywpc
21
22
23async def main():
24    ## Get Python driver version
25    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
26
27    ## Create device handle
28    dev = pywpc.EthanP()
29
30    ## Connect to device
31    try:
32        dev.connect("192.168.1.110") ## Depend on your device
33    except Exception as err:
34        pywpc.printGenericError(err)
35        ## Release device handle
36        dev.close()
37        return
38
39    try:
40        ## Parameters setting
41        port = 0 ## Depend on your device
42        resistance_ratio = [0.5, 0.2, 0.8, 0.7]
43
44        ## Get firmware model & version
45        driver_info = await dev.Sys_getDriverInfo_async()
46        print("Model name: " + driver_info[0])
47        print("Firmware version: " + driver_info[-1])
48
49        ## Open DPOT
50        err = await dev.DPOT_open_async(port)
51        print(f"DPOT_open_async in port {port}, status: {err}")
52
53        ## Write all channels
54        err = await dev.DPOT_writeAllChannel_async(port, resistance_ratio)
55        print(f"DPOT_writeAllChannel_async in port {port}, status: {err}")
56
57        ## Close DPOT
58        err = await dev.DPOT_close_async(port)
59        print(f"DPOT_close_async in port {port}, status: {err}")
60
61    except Exception as err:
62        pywpc.printGenericError(err)
63
64    ## Disconnect device
65    dev.disconnect()
66
67    ## Release device handle
68    dev.close()
69
70    return
71def main_for_spyder(*args):
72    if asyncio.get_event_loop().is_running():
73        return asyncio.create_task(main(*args)).result()
74    else:
75        return asyncio.run(main(*args))
76if __name__ == '__main__':
77    asyncio.run(main()) ## Use terminal
78    # await main() ## Use Jupyter or IPython(>=7.0)
79    # main_for_spyder() ## Use Spyder