-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
29 lines (24 loc) · 784 Bytes
/
Copy pathtest.py
File metadata and controls
29 lines (24 loc) · 784 Bytes
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
import time
import minimalmodbus
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', slaveaddress=49, debug=False)
instrument.serial.baudrate = 921600
instrument.serial.baudrate = 115200
instrument.serial.parity = minimalmodbus.serial.PARITY_NONE
instrument.serial.timeout = 2
communication = False
while communication == False:
time.sleep(1)
try:
instrument.read_float(43030, 4, 2, 3)
except:
print("No communication with sensor, trying again...")
else:
communication = True
print("Communication with sensor established.")
time.sleep(2)
while True:
val = instrument.read_float(43030, 4, 2, 3)
mystring = ' '.join([str(x) for x in val])
myfloat = float(mystring)
rndfloat = round(myfloat, 2)
print(rndfloat)