[Python] Python pymodbus can't read Mitsubishi Parameters

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have to read 1 parameter from my Mitsubishi Melservo J4, more specifically it is a MR-J4-40A-RJ. I can actually read parameters from a program called QModMaster. The settings for the connection are these:

    Settings image 1

    Settings image 2

    Summarized are:

    • Modbus mode: RTU
    • Slave addr: 1
    • Scan rate: 1000 ms
    • Function code: Read Holding Registers (0x03)
    • Start Address: 2103 Hex
    • Nuber of registers: 2
    • Serial device: COM
    • Serial port: 7
    • Baud: 115200
    • Data Bits: 8
    • Stop Bits: 2
    • Parity: None
    • RTS: Enable

    My python code is this, and is not working because it goes in timeout before getting some data:

    from pymodbus.client import ModbusSerialClient as ModbusClient
    from pymodbus.payload import BinaryPayloadDecoder
    from pymodbus.constants import Endian
    from pymodbus.exceptions import ModbusIOException

    # Create Modbus client instance
    client = ModbusClient(
    method='rtu',
    port='COM7',
    baudrate=115200,
    parity='N',
    stopbits=2,
    bytesize=8,
    timeout=1,
    rtscts=True
    )

    # Connect to the serial port
    connection = client.connect()
    if connection:
    print("Connected to the Modbus server")
    else:
    print("Failed to connect to the Modbus server")

    # Register address and number of registers to read
    register_address = 0x2103 # 2103h in hexadecimal
    num_registers = 2

    # Reading the registers
    try:
    response = client.read_holding_registers(register_address, num_registers, unit=1)
    if not isinstance(response, ModbusIOException):
    # Decode the response
    decoder = BinaryPayloadDecoder.fromRegisters(response.registers, byteorder=Endian.Big, wordorder=Endian.Big)
    parameter_value = decoder.decode_32bit_int()
    print(f"Parameter PC03 value: {parameter_value}")
    else:
    print(f"Error reading registers: {response}")
    except Exception as e:
    print(f"Exception: {e}")

    # Close the client
    client.close()


    And i get this error from the "response": Error reading registers: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 4 bytes (0 received)

    From the documentation this is the 2103h parameter: Parameter Image

    I hope i was clear, ask any question i will give further info.

    Thanks.

    I tried my python code, i was expecting at least some byte, but i'm getting 0 bytes.

    Continue reading...

Compartilhe esta Página