DPOT write by channel

 1'''
 2DPOT - DPOT_writeByChannel.py with asynchronous mode.
 3
 4This example demonstrates how to write digital potentiometer resistance to the specefic 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        channel = 0
42        resistance_ratio = 0.5
43        timeout = 3 ## second
44
45        ## Get firmware model & version
46        driver_info = dev.Sys_getDriverInfo(timeout)
47        print("Model name: " + driver_info[0])
48        print("Firmware version: " + driver_info[-1])
49
50        ## Open DPOT
51        err = dev.DPOT_open(port, timeout)
52        print(f"DPOT_open in port {port}, status: {err}")
53
54        ## Write on the channel
55        err = dev.DPOT_writeByChannel(port, channel, resistance_ratio, timeout)
56        print(f"DPOT_writeByChannel in port {port} channel {channel}, status: {err}")
57
58        ## Close DPOT
59        err = dev.DPOT_close(port, timeout)
60        print(f"DPOT_close in port {port}, status: {err}")
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
71
72if __name__ == '__main__':
73    main()