0

Sorry for my bad English.

I am trying to read data by the Modbus RTU method (library: minimalmodbus) but have a problem.

This is my 'Modbus Poll' display. 'Modbus Poll' display

I would like to read data by using minimalmodbus.

import minimalmodbus
import serial

instrument = minimalmodbus.Instrument('COM5', 1)  # port name, slave address (in decimal)
instrument.serial.port = 'COM5'                     # this is the serial port name
instrument.serial.baudrate = 9600         # Baud
instrument.serial.bytesize = 8
instrument.serial.parity   = serial.PARITY_NONE
instrument.serial.stopbits = 1
instrument.serial.timeout  = 0.1        # seconds
instrument.address = 1                         # this is the slave address number
instrument.mode = minimalmodbus.MODE_RTU   # rtu or ascii mode

result = instrument.read_float(0, 4, 20)
print(result)

But, I keep failing. Can please someone help me with how to read data?

Progman
  • 16,827
  • 6
  • 33
  • 48
  • To replicate your modbus poll setup, you'll want to use [read_registers(registeraddress: int, number_of_registers: int, functioncode: int = 3)](https://minimalmodbus.readthedocs.io/en/stable/apiminimalmodbus.html#minimalmodbus.Instrument.read_registers), for your case `instrument.read_registers(0, 20, 4)`, this will return a list of the twenty input registers. – import random Aug 19 '22 at 07:14

0 Answers0