RTD read channel status

 1'''
 2Temperature_RTD - RTD_read_channel_status.py with asynchronous mode.
 3
 4This example demonstrates how to get status in two channels from USBDAQF1RD.
 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    ## Get Python driver version
34    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
35
36    ## Create device handle
37    dev = pywpc.USBDAQF1RD()
38
39    ## Connect to device
40    try:
41        dev.connect("default")  ## Depend on your device
42    except Exception as err:
43        pywpc.printGenericError(err)
44        ## Release device handle
45        dev.close()
46        return
47
48    try:
49        ## Parameters setting
50        port = 1  ## Depend on your device
51        ch0 = 0
52        ch1 = 1
53
54        ## Get firmware model & version
55        driver_info = await dev.Sys_getDriverInfo_async()
56        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
57
58        ## Open RTD
59        err = await dev.Thermal_open_async(port)
60        print(f"Thermal_open_async in port {port}, status: {err}")
61
62        ## Set RTD port and get status in channel 0
63        status = await dev.Thermal_getStatus_async(port, ch0)
64        print(f"Thermal_getStatus_async in {ch0} status: {status}")
65
66        ## Set RTD port and get status in channel 1
67        status = await dev.Thermal_getStatus_async(port, ch1)
68        print(f"Thermal_getStatus_async in {ch1} status: {status}")
69
70        ## Close RTD
71        err = await dev.Thermal_close_async(port)
72        print(f"Thermal_close_async in port {port}, status: {err}")
73    except Exception as err:
74        pywpc.printGenericError(err)
75
76    finally:
77        ## Disconnect device
78        dev.disconnect()
79
80        ## Release device handle
81        dev.close()
82
83
84def main_for_spyder(*args):
85    if asyncio.get_event_loop().is_running():
86        return asyncio.create_task(main(*args)).result()
87    else:
88        return asyncio.run(main(*args))
89
90
91if __name__ == '__main__':
92    asyncio.run(main())  ## Use terminal
93    # await main()  ## Use Jupyter or IPython(>=7.0)
94    # main_for_spyder()  ## Use Spyder