4925 |
kaklik |
1 |
#!/usr/bin/env python |
|
|
2 |
import minimalmodbus |
|
|
3 |
import time |
|
|
4 |
|
|
|
5 |
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 1) # port name, slave address (in decimal) |
|
|
6 |
|
|
|
7 |
instrument.serial.port # this is the serial port name |
|
|
8 |
instrument.serial.baudrate = 9600 # Baud |
|
|
9 |
instrument.serial.bytesize = 8 |
|
|
10 |
instrument.serial.stopbits = 2 |
|
|
11 |
instrument.serial.timeout = 0.5 # seconds |
|
|
12 |
|
|
|
13 |
instrument.address = 0x1E # this is the slave address number |
|
|
14 |
instrument.mode = minimalmodbus.MODE_RTU # rtu or ascii mode |
|
|
15 |
|
|
|
16 |
instrument.write_register(0x01, 0x1F, 0) # Registernumber, value, number of decimals for storage |
|
|
17 |
|
|
|
18 |
time.sleep(0.5) |
|
|
19 |
|
|
|
20 |
## Read temperature (PV = ProcessValue) ## |
|
|
21 |
temperature = instrument.read_float(0x53, 3, 2) # Registernumber, number of decimals |
|
|
22 |
print temperature |
|
|
23 |
conductivity = instrument.read_float(0x55, 3, 2) # Registernumber, number of decimals |
|
|
24 |
print conductivity |
|
|
25 |
salinity = instrument.read_float(0x57, 3, 2) # Registernumber, number of decimals |
|
|
26 |
print salinity |
|
|
27 |
tds_kcl = instrument.read_float(0x59, 3, 2) # Registernumber, number of decimals |
|
|
28 |
print tds_kcl |
|
|
29 |
|
|
|
30 |
|
|
|
31 |
## Change temperature setpoint (SP) ## |
|
|
32 |
|