ModbusMaster library. Poor performances?

Hello

I’m using an ESP32-P4 and the library ModbusMaster to communicate with a Modbus device.

But I’m facing a curious behavior of the library.

The program needs 13 seconds to collect all the data needed over modbus. And obviously that too long to wait.

At first, I thought there were too much requests, but it’s only about 150 readings of holding registers. That results 300bytes of data as response. That’s nothing, especially at a baud rate of 115200.

What is going on?

Have you the same poor performances as I do with this ModbusMaster library?

Thank you

Please read and use this link: How to get the best out of this forum - Development Tools / IDE 1.x - Arduino Forum

Please post at least the code. Else, please post a crystal ball.

It’s not about my code.
Well my question actually is:

Have you the same poor performances as I do with this ModbusMaster library?

That’s it.

No.

If you don't post sufficient information, no-one can answer.
I doubt that the library is pushing a brake pedal, so the reason is likely something else.
How are you making the requests for 150 registers?

Modbus protocol limits the nro of registers to 125 in one request.
Modbusmaster library has default response buffer of 64. You can increase it though...

I read the registries individually. Most of them aren’t contiguous, I can’t reduce the number of requests significantly.

The driver look like so:

uint16_t RexDriver::readU16HoldingRegisters(uint16_t reg, uint16_t quantity){
  if (xSemaphoreTake(driver_mutex, SEMAPHORE_TIMEOUT) == pdTRUE){
    if (!isTimedOut){
      uint8_t result = node.readHoldingRegisters(reg, quantity);
      if (result == ModbusMaster::ku8MBSuccess){
        uint16_t response = node.getResponseBuffer(0x00);
        xSemaphoreGive(driver_mutex);
        return response;
      }else{ 
        if (result == ModbusMaster::ku8MBResponseTimedOut){
          //createTimeOutTask();
        }    
      }
    }
    xSemaphoreGive(driver_mutex);
  }
  
  return DATA_FAILURE_U16;
}

And calls like:

uint16_t RexDriver::getControllerDiagnostic(){
  return readU16HoldingRegisters(REG_CONTROLLER_DIAG, 1);
}

so how you arrive to 300 bytes?

300 bytes of usable data.

150 x uint16_t

With the communication overhead it’s of course much more than 300bytes that are passing thought the RS485 bus, but still, should be faster than that.

Look, one request is 8 bytes and one response is 7 bytes.

Ok.

That makes 1.2kB TX & 1kB RX.

It’s not a lot for an RS485 bus at 115200 baud rate.

No, but 2250 bytes is not 300.
And there are 300 transactions, with some delays on both sides.
I'm not able to guess beyond this.