0

Running a simple modbus program;

import time
import minimalmodbus
minimalmodbus.BAUDRATE = 9600                            #changed to suit snapper+ default
slave = minimalmodbus.Instrument('/dev/ttyUSB0', 1)      # port name, slave address (in decimal)
slave.serial.timeout  = 0.1                              # doubled from the default 0.05s
slave.debug = True
try:
  for x in range(207, 210):
    print x, slave.read_register(x, 1)
    time.sleep(.1)
except IOError:
    print("no modbus response")

it outputs;

207
MinimalModbus debug mode. Writing to instrument (expecting 7 bytes back): '\x01\x03\x00\xcf\x00\x01\xb45' (01 03 00 CF 00 01 B4 35)
MinimalModbus debug mode. No sleep required before write. Time since previous read: 1496625677952.7 ms, minimum silent period: 4.01 ms.
MinimalModbus debug mode. Response from instrument: '\x01\x03\x02\x01\xc28E' (01 03 02 01 C2 38 45) (7 bytes), roundtrip time: 35.2 ms. Timeout setting: 100.0 ms.

45.0
208
MinimalModbus debug mode. Writing to instrument (expecting 7 bytes back): '\x01\x03\x00\xd0\x00\x01\x85\xf3' (01 03 00 D0 00 01 85 F3)
MinimalModbus debug mode. No sleep required before write. Time since previous read: 102.5 ms, minimum silent period: 4.01 ms.
MinimalModbus debug mode. Response from instrument: '\x01\x03\x02\x00yy\xa6' (01 03 02 00 79 79 A6) (7 bytes), roundtrip time: 35.0 ms. Timeout setting: 100.0 ms.

12.1
209
MinimalModbus debug mode. Writing to instrument (expecting 7 bytes back): '\x01\x03\x00\xd1\x00\x01\xd43' (01 03 00 D1 00 01 D4 33)
MinimalModbus debug mode. No sleep required before write. Time since previous read: 102.3 ms, minimum silent period: 4.01 ms.
MinimalModbus debug mode. Response from instrument: '\x01\x03\x02\x00\x05xG' (01 03 02 00 05 78 47) (7 bytes), roundtrip time: 33.9 ms. Timeout setting: 100.0 ms.

0.5

I don't understand why minimal modbus is dividing by 10? Easy enough to fix I guess, just multiply by 10, but curious as to why the default interpretation is that stuff in the registers has been multiplied by 10 already?

1 Answers1

-1

To not have the divided result change the command to:

print x, slave.read_register(x)
Darth Vader
  • 4,206
  • 24
  • 45
  • 69