<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Weird QModbusClient output]]></title><description><![CDATA[<p dir="auto">I have a simple class that reads data from a Modbus RTU device. Some code:</p>
<pre><code>Modbus485::Modbus485(QObject *parent) : QThread(parent)
{
    _device = nullptr;
}

bool Modbus485::open(QString serialPort, QString DE_bank, int DE_pin, QSerialPort::BaudRate baudRate, QSerialPort::Parity parity, QSerialPort::DataBits dataBits, QSerialPort::StopBits stopBits)
{
    _gpio-&gt;set(PIN_DE, false);

    if (_device) delete _device;
    _device = new QModbusRtuSerialMaster();
    QObject::connect(_device, &amp;QModbusClient::errorOccurred, [this](QModbusDevice::Error)
    {
        qInfo().noquote() &lt;&lt; Utils::timestamp() &lt;&lt; "[RS485] Error occurred:" &lt;&lt; _device-&gt;errorString();
        return false;
    });

    _device-&gt;setConnectionParameter(QModbusDevice::SerialPortNameParameter, serialPort);
    _device-&gt;setConnectionParameter(QModbusDevice::SerialBaudRateParameter, baudRate);
    _device-&gt;setConnectionParameter(QModbusDevice::SerialParityParameter, parity);
    _device-&gt;setConnectionParameter(QModbusDevice::SerialDataBitsParameter, dataBits);
    _device-&gt;setConnectionParameter(QModbusDevice::SerialStopBitsParameter, stopBits);
    _device-&gt;setTimeout(250);
    _device-&gt;setNumberOfRetries(0);

    if (!_device-&gt;connectDevice())
    {
        qInfo().noquote() &lt;&lt; Utils::timestamp() &lt;&lt; "[RS485] Connection failed:" &lt;&lt; _device-&gt;errorString();
        return false;
    }

    return true;
}

bool Modbus485::read(int startAddress, quint16 count)
{
    _gpio-&gt;set(PIN_DE, true);

    QModbusDataUnit request = QModbusDataUnit(QModbusDataUnit::HoldingRegisters, startAddress, count);
    if (auto *reply = _device-&gt;sendReadRequest(request, _serverAddress))
    {
        QTimer::singleShot(30, [this]() { _gpio-&gt;set(PIN_DE, false); });
        if (!reply-&gt;isFinished()) QObject::connect(reply, &amp;QModbusReply::finished, [reply]()
        {
            if (reply-&gt;error() == QModbusDevice::NoError)
            {
                const QModbusDataUnit unit = reply-&gt;result();
                qDebug() &lt;&lt; unit.values(); // read ok!!!
                return true;
            }
            else if (reply-&gt;error() == QModbusDevice::ProtocolError)
            {
                qInfo().noquote() &lt;&lt; Utils::timestamp() &lt;&lt; "[RS485] Protocol error:" &lt;&lt; reply-&gt;errorString() &lt;&lt; reply-&gt;rawResult().exceptionCode();
                return false;
            }
            else
            {
                qInfo().noquote() &lt;&lt; Utils::timestamp() &lt;&lt; "[RS485] Error occurred:" &lt;&lt; reply-&gt;errorString();
                return false;
            }
            reply-&gt;deleteLater();
        });
        else
        {
            qDebug() &lt;&lt; "REPLY FINISHED!";
            delete reply;
            return false;
        }
    }
    else
    {
        qInfo().noquote() &lt;&lt; Utils::timestamp() &lt;&lt; "[RS485] Generic error:" &lt;&lt; _device-&gt;errorString();
        _gpio-&gt;set(PIN_DE, false);
        return false;
    }

    return false;
}
</code></pre>
<p dir="auto">But when I try to read something I get this debug output:</p>
<pre><code>&gt;&gt; "Tx: 0x01030031000295c4"
Debug: (RTU client) Sent Serial ADU: 0x01030031000295c4 ((null):0, (null))
Debug: (RTU client) Send failed: 0x0300310002 ((null):0, (null))
[RS485] Error occurred: Request timeout
Debug: (RTU client) Sent Serial PDU: 0x0300310002 ((null):0, (null))
&gt;&gt; "Tx: 0x01030031000295c4"
Debug: (RTU client) Sent Serial ADU: 0x01030031000295c4 ((null):0, (null))
Debug: (RTU client) Send successful: 0x0300310002 ((null):0, (null))
&lt;&lt; 37 "Rx: 0x0103040000138d37"
Debug: (RTU client) Response buffer: "0103040000138d37" ((null):0, (null))
Debug: (RTU client) Incomplete ADU received, ignoring ((null):0, (null))
&lt;&lt; 39 "Rx: 0x0103040000138d3766"
Debug: (RTU client) Response buffer: "0103040000138d3766" ((null):0, (null))
Debug: (RTU client) Received ADU: "0103040000138d3766" ((null):0, (null))
Debug: QVector(0, 5003) 
</code></pre>
<p dir="auto">Questions:</p>
<ol>
<li>how can the sending fail?</li>
<li>what does mean Sent Serial PDU after Send failed?</li>
<li>why there are two receiving events, where the first one is incomplete? Is there anything I can set to avoid this?</li>
</ol>
]]></description><link>https://forum.qt.io/topic/116999/weird-qmodbusclient-output</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 09:22:48 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/116999.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 14 Jul 2020 11:18:14 GMT</pubDate><ttl>60</ttl></channel></rss>