TC read channel data

 1'''
 2Temperature_TC - TC_read_channel_data.py with synchronous 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-2024 WPC Systems Ltd. All rights reserved.
18'''
19
20## Python
21import time
22
23## WPC
24
25from wpcsys import pywpc
26
27def 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        ch = 1
47        over_sampling_mode = 0  ## 0:1 sample, 1:2 samples, 2:4 sample, 3:8 samples, 4:16 samples
48        thermo_type = 3         ## 0:B type, 1:E type, 2:J type, 3:K type
49                                ## 4:N type, 5:R type, 6:S type, 7:T type
50        timeout = 3 ## second
51
52        ## Get firmware model & version
53        driver_info = dev.Sys_getDriverInfo(timeout)
54        print("Model name: " + driver_info[0])
55        print("Firmware version: " + driver_info[-1])
56
57        ## Open thermo
58        err = dev.Thermal_open(port, timeout)
59        print(f"Thermal_open in port {port}, status: {err}")
60
61        ## Set thermo port and set over-sampling mode to no over-sampling in channel 1
62        err = dev.Thermal_setOverSampling(port, ch, over_sampling_mode, timeout)
63        print(f"Thermal_setOverSampling in channel {ch} in port {port}, status: {err}")
64
65        ## Set thermo port and set K type in channel 1
66        err = dev.Thermal_setType(port, ch, thermo_type, timeout)
67        print(f"Thermal_setType in channel {ch} in port {port}, status: {err}")
68
69        ## Wait for at least 500 ms after setting type or oversampling
70        time.sleep(0.5) ## delay [s]
71
72        ## Set thermo port and read thermo in channel 1
73        data = dev.Thermal_readSensor(port, ch, timeout)
74        print(f"Read sensor in channel {ch} in port {port}: {data} deg C")
75
76        ## Close thermo
77        err = dev.Thermal_close(port, timeout)
78        print(f"Thermal_close in port {port}, status: {err}")
79    except Exception as err:
80        pywpc.printGenericError(err)
81
82    ## Disconnect device
83    dev.disconnect()
84
85    ## Release device handle
86    dev.close()
87
88    return
89
90if __name__ == '__main__':
91    main()