emelianov / modbus-esp8266

Most complete Modbus library for Arduino. A library that allows your Arduino board to communicate via Modbus protocol, acting as a master, slave or both. Supports network transport (Modbus TCP) and Serial line/RS-485 (Modbus RTU). Supports Modbus TCP Security for ESP8266/ESP32.
Other
534 stars 190 forks source link

Seeking Guidance on Controlling Retry Mechanism in modbus-esp8266 Library #345

Closed alansehsu closed 6 months ago

alansehsu commented 8 months ago

Hello! I am reaching out for some guidance and help regarding a specific need and challenge I encountered while using the modbus-esp8266 library for a project.

In our project, which involves the use of Modbus RTU communication, we have observed that if a device is not powered on or does not respond, the library automatically attempts to retry the previously inputted writeHreg command. This behavior is not always desirable in certain scenarios. Thus, we are looking for ways to more precisely control this retry mechanism. Specifically, we are interested in capabilities or settings that relate to the following aspects:

Stopping retries: We'd appreciate an option to stop automatic retries when a device does not respond. Removing submitted commands: If it is known that certain commands should no longer be attempted due to some conditions, we'd like to remove these commands from the pending queue. Setting the number of retries: If possible, we'd like to set a limit on the number of retries to prevent infinite attempts. During our attempts to find solutions, we first checked the Modbus.cpp source file but did not find commands or settings directly related to our needs. We then focused on RTU communication and reviewed the ModbusSettings.h file; although we found some settings related to timeouts and maximum read wait times, they seemed not to directly address our queries.

We would greatly appreciate any advice on how we might implement the above requirements or guidance on where to look for possible solutions. Do we need to customize the library, or are there existing parameter settings that could meet our needs? Any suggestions or directions would be immensely helpful.

Thank you for taking the time to read this message. I look forward to your response.

Best regards

emelianov commented 7 months ago

The library ModbusRTU implementation does not perform any buffering or other data manipulations during sending. So data frame is sending exactly once during corresponding function. Any data sent retry attempts are performed outside the library. Definitely.