Skip to content

Response address xxx is different from request address 33 #168

Open
@Syavash-kazemi

Description

@Syavash-kazemi

Hi,
I am trying to read some Modbus addresses from a multi-transducer through a serial port. I am running a loop to get around 5 readings per second.

Here is a snippet of the code:

    try:
        # Connect to the slave
        master = modbus_rtu.RtuMaster(
            serial.Serial(port=CONFIGS["PORT"], baudrate=CONFIGS["SERIAL_BAUDRATE"],
                          bytesize=CONFIGS["SERIAL_BYTESIZE"], parity=CONFIGS["SERIAL_PARITY"],
                          stopbits=CONFIGS["SERIAL_STOPBITS"], xonxoff=0)
        )
        master.set_timeout(0.5)
        master.set_verbose(False)
        logger.info("connected")
        LOGGER_MTR.debug("modbus slave connected")

        while True:
            utc_now = datetime.utcnow()

            master.open()
            try:
                frequency = master.execute(slave=CONFIGS["MODBUS_SLAVE"],
                                           function_code=CONFIGS["MODBUS_HZ_FUNCTION_CODE"],
                                           starting_address=CONFIGS["MODBUS_HZ_STARTING_ADDRESS"],
                                           quantity_of_x=CONFIGS["MODBUS_HZ_BYTES"])
                frequency = unsigned_measurement_to_float(frequency)
            except Exception as try_error:
                LOGGER_MTR.error("failed reading from slave")
                LOGGER_MTR.error(try_error)
                frequency = None
            master.close()
           
            time.sleep(0.15)

So the loop works well and I get readings. However, sometimes I get the next error (this is just an example) for some minutes, before coming back and streaming values again:

...
failed reading from slave
Response address 193 is different from request address 33
Freq: None
failed reading from slave
Response address 193 is different from request address 33
....

So MODBUS_SLAVE is 33, but I don't understand why the master is calling the address 193. I have seen any number being called between 1 and 255.

Am I missing something? What could it be the reason to end up

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions