相关文章推荐
空虚的显示器  ·  module 'cv2' has no ...·  5 小时前    · 
聪明伶俐的核桃  ·  python socket ...·  2 小时前    · 
爱旅游的荔枝  ·  ADB权限列表-CSDN博客·  1 月前    · 
深情的饺子  ·  python pyqt5 ...·  1 年前    · 
大力的面包  ·  sql - Error with ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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?

To replicate your modbus poll setup, you'll want to use read_registers(registeraddress: int, number_of_registers: int, functioncode: int = 3), for your case instrument.read_registers(0, 20, 4), this will return a list of the twenty input registers. – import random Aug 19, 2022 at 7:14

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.