4-20ma / ModbusMaster

Enlighten your Arduino to be a Modbus master
http://4-20ma.io/ModbusMaster/
Apache License 2.0
599 stars 353 forks source link

ReadHoldingRegisters takes 2seconds #182

Open JODLatGit opened 1 year ago

JODLatGit commented 1 year ago

I am using a Seneca Z-8NTC to readout NTC's resistors. I have seen that underneath commands:

// Read 16 registers starting at 74)
waitPeriod = millis();
result = Modbus1.readHoldingRegisters(74, 16);
waitPeriod1 = millis();
if (result == Modbus1.ku8MBSuccess)
  {
  NTC2 = Convert4bytesToFloat(2);  (In the function I use getResponseBuffer)
  NTC4 = Convert4bytesToFloat(6);
  NTC6 = Convert4bytesToFloat(10);
  }

The command readHoldingRegisters takes up 2 seconds ? It of course slows down the response time of my Controllino application .

The serial settings are :

// Init RS485 Controllino_RS485Init(19200); //NTC module Modbus1.begin(2, Serial3 );

Do I something wrong ? What can I do to let it response faster ? It is always almost exactly 2 seconds measured with the millis() function.

ModbusMaster version

[Version : 2.0.1]

Arduino IDE version

[Version : 1.8.19]

Arduino Hardware

[Controllino Max]

JODLatGit commented 1 year ago

Did another test instead of reading 16 registers I read only 2 but the execution time stays the same 2 sec . It seems that readHoldingRegisters cmd takes up 2 seconds ??

JODLatGit commented 1 year ago

Another test learns me that apparently changing underneath the value from 2000 to 50 in the header file the readHoldingRegisters command response in 50ms instead of the 2000 !!?? // Modbus timeout [milliseconds] static const uint16_t ku16MBResponseTimeout = 50; ///< Modbus timeout [milliseconds] Seems that the readHoldingRegisters command isn't working properly !!! Took almost 1 day to solve it.

rob040 commented 1 year ago

Another test learns me that apparently changing underneath the value from 2000 to 50 in the header file the readHoldingRegisters command response in 50ms instead of the 2000 !!?? // Modbus timeout [milliseconds] static const uint16_t ku16MBResponseTimeout = 50; ///< Modbus timeout [milliseconds] Seems that the readHoldingRegisters command isn't working properly !!! Took almost 1 day to solve it.

That is not a solution, but a workaround. Still, if your implementation is hit by the timeout, be it 2 or 0.05 seconds, then there is something wrong with your communication or modbus slave. please check the return value of readHoldingRegisters (). It should be 0 on success, but will be ku8MBResponseTimedOut (0xE2) in case of timeout.