1'''
2Temperature_TC - TC_read_channel_data.py with synchronous mode.
3
4This example demonstrates how to read thermocouple from EthanT.
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 time
25
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.EthanT()
33
34 ## Connect to device
35 try:
36 dev.connect("192.168.1.110") ## 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 4:N type, 5:R type, 6:S type, 7:T type
49 timeout = 3 ## [sec]
50
51 ## Get firmware model & version
52 driver_info = dev.Sys_getDriverInfo(timeout)
53 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
54
55 ## Open thermo
56 err = dev.Thermal_open(port, timeout)
57 print(f"Thermal_open in port {port}, status: {err}")
58
59 ## Set thermo port and set over-sampling mode to no over-sampling in channel 1
60 err = dev.Thermal_setOverSampling(port, ch, over_sampling_mode, timeout)
61 print(f"Thermal_setOverSampling in channel {ch} in port {port}, status: {err}")
62
63 ## Set thermo port and set K type in channel 1
64 err = dev.Thermal_setType(port, ch, thermo_type, timeout)
65 print(f"Thermal_setType in channel {ch} in port {port}, status: {err}")
66
67 ## Wait for at least 500 ms after setting type or oversampling
68 time.sleep(0.5) ## delay [sec]
69
70 ## Set thermo port and read thermo in channel 1
71 data = dev.Thermal_readSensor(port, ch, timeout)
72 print(f"Read sensor in channel {ch} in port {port}: {data} deg C")
73
74 ## Close thermo
75 err = dev.Thermal_close(port, timeout)
76 print(f"Thermal_close in port {port}, status: {err}")
77 except Exception as err:
78 pywpc.printGenericError(err)
79
80 finally:
81 ## Disconnect device
82 dev.disconnect()
83
84 ## Release device handle
85 dev.close()
86
87
88if __name__ == '__main__':
89 main()