Skip to content

[Windows RTU] modbus_receive() ignores response/byte timeout unless indication_timeout is set #822

@draculamx

Description

@draculamx

Description

When using modbus_receive() in RTU slave mode on Windows, the response_timeout and byte_timeout settings are ignored unless modbus_set_indication_timeout() is also called.

This means that even if modbus_set_response_timeout() and modbus_set_byte_timeout() are properly set, modbus_receive() will block indefinitely (no timeout behavior) unless modbus_set_indication_timeout() is called.

This is a serious issue because:

  • modbus_set_indication_timeout() is intended for master-side use only (waiting for slave response)
  • It should not affect slave-side modbus_receive() behavior
  • This creates a hidden dependency and makes timeout configuration non-intuitive

Steps to Reproduce

  1. Create a Modbus RTU slave on Windows (e.g., C++ Builder, MinGW, MSVC)
  2. Set only response and byte timeouts:
    modbus_set_response_timeout(ctx, 0, 300000);  // 300ms
    modbus_set_byte_timeout(ctx, 0, 300000);      // 300ms

Call modbus_receive(ctx, query) → blocks forever, even with no data
Now add:

modbus_set_indication_timeout(ctx, 0, 300000);
modbus_receive() now respects the timeout and returns on timeout
Expected Behavior
modbus_receive() should respect response_timeout and byte_timeout regardless of whether indication_timeout is set
indication_timeout is irrelevant for slave-side reception and should not control the enablement of timeout logic
Actual Behavior
modbus_receive() only enables timeout mechanism if indication_timeout has been set
Otherwise, it falls back to infinite blocking (no SetCommTimeouts() applied?)
Environment
libmodbus version: 3.1.10 (and likely earlier)
OS: Windows 10/11
Compiler: C++ Builder 10.2.3, MinGW, MSVC
Backend: RTU (serial)
Root Cause (Likely)
The internal logic in rtu/win32.c or modbus-rtu.c may incorrectly use the indication_timeout_set flag to decide whether to apply SetCommTimeouts() or enable non-blocking behavior, even for slave-side operations.

Suggested Fix
Ensure that response_timeout and byte_timeout are independently respected for modbus_receive(), and remove the unintended dependency on indication_timeout.

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