DPOT read by channel

 1'''
 2DPOT - DPOT_readByChannel.py with synchronous mode.
 3
 4This example demonstrates how to read digital potentiometer resistance by 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 time
17
18## WPC
19
20from wpcsys import pywpc
21
22def main():
23    ## Get Python driver version
24    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
25
26    ## Create device handle
27    dev = pywpc.EthanP()
28
29    ## Connect to device
30    try:
31        dev.connect("192.168.1.110") ## Depend on your device
32    except Exception as err:
33        pywpc.printGenericError(err)
34        ## Release device handle
35        dev.close()
36        return
37
38    try:
39        ## Parameters setting
40        port = 0 ## Depend on your device
41        timeout = 3 ## second
42
43        ## Get firmware model & version
44        driver_info = dev.Sys_getDriverInfo(timeout)
45        print("Model name: " + driver_info[0])
46        print("Firmware version: " + driver_info[-1])
47
48        ## Open DPOT
49        err = dev.DPOT_open(port, timeout)
50        print(f"DPOT_open in port {port}, status: {err}")
51
52        ## Read all channels by for loop
53        for i in range(4):
54            resistance_ratio = dev.DPOT_readByChannel(i, timeout)
55            print(f"resistance_ratio in channel {i}: {resistance_ratio}")
56
57        ## Close DPOT
58        err = dev.DPOT_close(port, timeout)
59        print(f"DPOT_close in port {port}, status: {err}")
60    except Exception as err:
61        pywpc.printGenericError(err)
62
63    ## Disconnect device
64    dev.disconnect()
65
66    ## Release device handle
67    dev.close()
68
69    return
70
71if __name__ == '__main__':
72    main()