TC read channel data

 1'''
 2Temperature_TC - TC_read_channel_data.py with asynchronous mode.
 3
 4This example demonstrates how to read thermocouple from USBDAQF1TD.
 5
 6First, it shows how to open thermal port and configure thermal parameters.
 7Second, read channel 1 thermocouple data.
 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.USBDAQF1TD()
35
36    ## Connect to device
37    try:
38        dev.connect("default")  ## 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        ch = 1
49        over_sampling_mode = 0  ## 0:1 sample, 1:2 samples, 2:4 sample, 3:8 samples, 4:16 samples
50        thermo_type = 3  ## 0:B type, 1:E type, 2:J type, 3:K type 4:N type, 5:R type, 6:S type, 7:T type
51
52        ## Get firmware model & version
53        driver_info = await dev.Sys_getDriverInfo_async()
54        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
55
56        ## Open thermo
57        err = await dev.Thermal_open_async(port)
58        print(f"Thermal_open_async in port {port}, status: {err}")
59
60        ## Set thermo port and set over-sampling mode to no over-sampling in channel 1
61        err = await dev.Thermal_setOverSampling_async(port, ch, over_sampling_mode)
62        print(f"Thermal_setOverSampling_async in port {port}, status: {err}")
63
64        ## Set thermo port and set K type in channel 1
65        err = await dev.Thermal_setType_async(port, ch, thermo_type)
66        print(f"Thermal_setType_async in port {port}, status: {err}")
67
68        ## Wait for at least 500 ms after setting type or oversampling
69        await asyncio.sleep(0.5)  ## delay [sec]
70
71        ## Set thermo port and read thermo in channel 1
72        data = await dev.Thermal_readSensor_async(port, ch)
73        print(f"Read sensor in channel {ch} in port {port}: {data} deg C")
74
75        ## Close thermo
76        err = await dev.Thermal_close_async(port)
77        print(f"Thermal_close_async in port {port}, status: {err}")
78    except Exception as err:
79        pywpc.printGenericError(err)
80
81    finally:
82        ## Disconnect device
83        dev.disconnect()
84
85        ## Release device handle
86        dev.close()
87
88
89def main_for_spyder(*args):
90    if asyncio.get_event_loop().is_running():
91        return asyncio.create_task(main(*args)).result()
92    else:
93        return asyncio.run(main(*args))
94
95
96if __name__ == '__main__':
97    asyncio.run(main())  ## Use terminal
98    # await main()  ## Use Jupyter or IPython(>=7.0)
99    # main_for_spyder()  ## Use Spyder