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