TC read channel status

 1'''
 2Temperature_TC - TC_read_channel_status.py with asynchronous mode.
 3
 4This example demonstrates how to get status from EthanT.
 5
 6First, it shows how to open thermal port
 7Second, get status from channel 0 and channel 1
 8Last, close thermal port.
 9
10-------------------------------------------------------------------------------------
11Please change correct serial number or IP and port number BEFORE you run example code.
12
13For other examples please check:
14    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
15See README.md file to get detailed usage of this example.
16
17Copyright (c) 2022-2025 WPC Systems Ltd. All rights reserved.
18'''
19
20## WPC
21from wpcsys import pywpc
22
23## Python
24import asyncio
25import sys
26sys.path.insert(0, 'src/')
27
28
29async def main():
30    ## Get Python driver version
31    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
32
33    ## Create device handle
34    dev = pywpc.EthanT()
35
36    ## Connect to device
37    try:
38        dev.connect("192.168.1.110")  ## Depend on your device
39    except Exception as err:
40        pywpc.printGenericError(err)
41        ## Release device handle
42        dev.close()
43        return
44
45    try:
46        ## Parameters setting
47        port = 1  ## Depend on your device
48        ch0 = 0
49        ch1 = 1
50
51        ## Get firmware model & version
52        driver_info = await dev.Sys_getDriverInfo_async()
53        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
54
55        ## Open thermo
56        err = await dev.Thermal_open_async(port)
57        print(f"Thermal_open_async in port {port}, status: {err}")
58
59        ## Set thermo port and get status in channel 0
60        status = await dev.Thermal_getStatus_async(port, ch0)
61        print(f"Thermal_getStatus_async in channel {ch0} in port {port}: {status}")
62
63        ## Set thermo port and get status in channel 1
64        status = await dev.Thermal_getStatus_async(port, ch1)
65        print(f"Thermal_getStatus_async in channel {ch1} in port {port}: {status}")
66
67        ## Close thermo
68        err = await dev.Thermal_close_async(port)
69        print(f"Thermal_close_async in port {port}, status: {err}")
70    except Exception as err:
71        pywpc.printGenericError(err)
72
73    finally:
74        ## Disconnect device
75        dev.disconnect()
76
77        ## Release device handle
78        dev.close()
79
80
81def main_for_spyder(*args):
82    if asyncio.get_event_loop().is_running():
83        return asyncio.create_task(main(*args)).result()
84    else:
85        return asyncio.run(main(*args))
86
87
88if __name__ == '__main__':
89    asyncio.run(main())  ## Use terminal
90    # await main()  ## Use Jupyter or IPython(>=7.0)
91    # main_for_spyder()  ## Use Spyder