37 lines
966 B
Python
Executable File
37 lines
966 B
Python
Executable File
import minimalmodbus
|
|
from definitions import _SENSORS
|
|
|
|
PORT='/dev/ttyRS485'
|
|
TESTREG = 150
|
|
|
|
#Set up instrument
|
|
instrument = minimalmodbus.Instrument( PORT, 1) #, mode = minimalmodbus.MODE_RTU)
|
|
|
|
#Make the settings explicit
|
|
instrument.serial.baudrate = 9600 # Baud
|
|
instrument.serial.bytesize = 8
|
|
instrument.serial.parity = minimalmodbus.serial.PARITY_NONE
|
|
instrument.serial.stopbits = 1
|
|
instrument.serial.timeout = 1 # seconds
|
|
|
|
# Good practice
|
|
instrument.close_port_after_each_call = True
|
|
|
|
instrument.clear_buffers_before_each_transaction = True
|
|
|
|
# Read temperatureas a float
|
|
# if you need to read a 16 bit register use instrument.read_register()
|
|
instrument.write_register (135, 0, 1)
|
|
instrument.write_register (137, 0, 1)
|
|
for i in _SENSORS:
|
|
try:
|
|
reg, name, unit, scale = i
|
|
print (name)
|
|
if type (reg) == type (1):
|
|
val = instrument.read_register (reg, 1)
|
|
print (" ", val)
|
|
else:
|
|
print (reg)
|
|
except:
|
|
print (i)
|