TC read channel status

 1'''
 2Temperature_TC - TC_read_channel_status.py with asynchronous mode.
 3
 4This example demonstrates how to get status from USBDAQF1TD.
 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-2024 WPC Systems Ltd. All rights reserved.
18'''
19
20## Python
21import asyncio
22
23## WPC
24
25from wpcsys import pywpc
26
27async def main():
28    ## Get Python driver version
29    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
30
31    ## Create device handle
32    dev = pywpc.USBDAQF1TD()
33
34    ## Connect to device
35    try:
36        dev.connect("default") ## Depend on your device
37    except Exception as err:
38        pywpc.printGenericError(err)
39        ## Release device handle
40        dev.close()
41        return
42
43    try:
44        ## Parameters setting
45        port = 1 ## Depend on your device
46        ch0 = 0
47        ch1 = 1
48
49        ## Get firmware model & version
50        driver_info = await dev.Sys_getDriverInfo_async()
51        print("Model name: " + driver_info[0])
52        print("Firmware version: " + driver_info[-1])
53
54        ## Open thermo
55        err = await dev.Thermal_open_async(port)
56        print(f"Thermal_open_async in port {port}, status: {err}")
57
58        ## Set thermo port and get status in channel 0
59        status = await dev.Thermal_getStatus_async(port, ch0)
60        print(f"Thermal_getStatus_async in channel {ch0} in port {port}: {status}")
61
62        ## Set thermo port and get status in channel 1
63        status = await dev.Thermal_getStatus_async(port, ch1)
64        print(f"Thermal_getStatus_async in channel {ch1} in port {port}: {status}")
65
66        ## Close thermo
67        err = await dev.Thermal_close_async(port)
68        print(f"Thermal_close_async in port {port}, status: {err}")
69    except Exception as err:
70        pywpc.printGenericError(err)
71
72    ## Disconnect device
73    dev.disconnect()
74
75    ## Release device handle
76    dev.close()
77
78    return
79
80def main_for_spyder(*args):
81    if asyncio.get_event_loop().is_running():
82        return asyncio.create_task(main(*args)).result()
83    else:
84        return asyncio.run(main(*args))
85
86if __name__ == '__main__':
87    asyncio.run(main()) ## Use terminal
88    # await main() ## Use Jupyter or IPython(>=7.0)
89    # main_for_spyder() ## Use Spyder