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-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 channel = 0
39 resistance_ratio = 0.5
40 timeout = 3 ## [sec]
41
42 ## Get firmware model & version
43 driver_info = dev.Sys_getDriverInfo(timeout)
44 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
45
46 ## Open DPOT
47 err = dev.DPOT_open(port, timeout)
48 print(f"DPOT_open in port {port}, status: {err}")
49
50 ## Write on the channel
51 err = dev.DPOT_writeByChannel(port, channel, resistance_ratio, timeout)
52 print(f"DPOT_writeByChannel in port {port} channel {channel}, status: {err}")
53
54 ## Close DPOT
55 err = dev.DPOT_close(port, timeout)
56 print(f"DPOT_close in port {port}, status: {err}")
57 except Exception as err:
58 pywpc.printGenericError(err)
59
60 finally:
61 ## Disconnect device
62 dev.disconnect()
63
64 ## Release device handle
65 dev.close()
66
67
68if __name__ == '__main__':
69 main()