Skip to content

diag_force_listen_only with no response expected always returns an error #2800

@scully-jmccarthy

Description

@scully-jmccarthy

When performing a diag_force_listen_only operation with no_response_expected=True and the device supports the command, and thus no response is expected, the pymodbus library always returns a spurious error.

Example:

    print("Set listen only")
    try:
        # See all calls in client_calls.py
        rr = await client.diag_force_listen_only(device_id=1, no_response_expected=True)
    except ModbusException as exc:
        print(f"Received ModbusException({exc}) from library")
        client.close()
        assert 0
    if rr.isError():
        print(f"Received exception from device ({rr})")

Output

Set diag listen only
2025-10-10 10:33:50,895 DEBUG transport:375 send: 0x1 0x8 0x0 0x4 0x0 0x0 0xa1 0xca
Received exception from device (ExceptionResponse(dev_id=1, function_code=255, exception_code=0))

I have confirmed with an oscilloscope that there is no response being sent back by the server device, so this exception response is internal to the library.

The behavior was validated to be correct when no_response_expected=False
Example:

    print("Set listen only")
    try:
        # See all calls in client_calls.py
        rr = await client.diag_force_listen_only(device_id=1, no_response_expected=False)
    except ModbusException as exc:
        print(f"Received ModbusException({exc}) from library")
        client.close()
        assert 0
    if rr.isError():
        print(f"Received exception from device ({rr})")

Output

Set listen only
2025-10-10 10:28:13,161 DEBUG transport:375 send: 0x1 0x8 0x0 0x4 0x0 0x0 0xa1 0xca
2025-10-10 10:28:15,147 DEBUG transport:375 Repeating....
2025-10-10 10:28:17,155 ERROR transaction:200 No response received after 1 retries, continue with next request
Received ModbusException(Modbus Error: [Input/Output] No response received after 1 retries, continue with next request) from library

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions