-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathampti04_4ch_pt100_read_loop.py
53 lines (41 loc) · 1.71 KB
/
ampti04_4ch_pt100_read_loop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import minimalmodbus
import time
ampti04 = minimalmodbus.Instrument('COM6', 1) # port name, slave address (in decimal)
ampti04.serial.port # this is the serial port name
ampti04.serial.baudrate = 9600 # Baud
ampti04.serial.bytesize = 8
ampti04.serial.parity = minimalmodbus.serial.PARITY_NONE
ampti04.serial.stopbits = 1
ampti04.serial.timeout = 0.2 # seconds
ampti04.address # this is the slave address number
ampti04.mode = minimalmodbus.MODE_RTU # rtu or ascii mode
ampti04.clear_buffers_before_each_transaction = True
ampti04.close_port_after_each_call = True
ampti04.clear_buffers_before_each_transaction = True
sleep_time=0.2
i=0
while i!=100:
try:
print("CH1:", ampti04.read_register(0,1,4)," C") #Read PT100 on channel 1, memory address 0, 1 decimal place, control code 4
except IOError:
print("Failed to read CH1")
time.sleep(sleep_time)
try:
print("CH2:", ampti04.read_register(1,1,4)," C") #Read PT100 on channel 2, memory address 1, 1 decimal place, control code 4
except IOError:
print("Failed to read CH2")
time.sleep(sleep_time)
try:
print("CH3:", ampti04.read_register(2,1,4)," C") #Read PT100 on channel 3, memory address 2, 1 decimal place, control code 4
except IOError:
print("Failed to read CH3")
time.sleep(sleep_time)
try:
print("CH4:", ampti04.read_register(3,1,4)," C") #Read PT100 on channel 4, memory address 3, 1 decimal place, control code 4
except IOError:
print("Failed to read CH4")
time.sleep(sleep_time)
print("==========================")
i+=1
ampti04.serial.close()