<?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[QSerialPort: readyRead() signal is emitted 2 times instead of 1 time]]></title><description><![CDATA[<p dir="auto">Hello everyone!</p>
<p dir="auto">Now I try to study using of QSerialPort with QThread. And during the study I got some strange thing: I get 2 readyRead() signals =&gt; 2 readyRead() slots, and I can't to construct response data as one.</p>
<p dir="auto">What I have:</p>
<ul>
<li>I have the class for QSerialPort, there are some slots for open port, for write to port, for read from port. Slot for reading from port s connected to readyRead() signal in constructor of the class:</li>
</ul>
<p dir="auto"><code>connect(serialPort, &amp;QSerialPort::readyRead, this, &amp;SerialPort_Class::slot_ReadInPort);</code></p>
<p dir="auto">Slot for writing to port:</p>
<pre><code>void SerialPort_Class::slot_WriteToPort(QByteArray writeData)
{
    qDebug() &lt;&lt; "SLOT WriteToPort" &lt;&lt; endl;
    if (serialPort-&gt;isOpen())
    {
        QByteArray readData = serialPort-&gt;readAll();

        qDebug() &lt;&lt; "Write Request = " &lt;&lt; writeData &lt;&lt; endl;

        serialPort-&gt;write(writeData);

        if (serialPort-&gt;waitForBytesWritten(1000))
        {}
        else
        {
            qDebug() &lt;&lt; "Write request TIMEOUT" &lt;&lt; endl;
        }
    }
}
</code></pre>
<p dir="auto">Slot for readyRead:</p>
<pre><code>void SerialPort_Class::slot_ReadInPort()
{
    QThread::msleep(1000);

    qDebug() &lt;&lt; "EMIT SendReadData" &lt;&lt; endl;
    emit signal_SendReadData("");
}
</code></pre>
<ul>
<li>I have the Thread for emitting of signal for writing to port after opening the port and after slot for readyRead() for processing of response data.</li>
</ul>
<p dir="auto">And what I get in the Debug log (only 1 write command per opening the port):</p>
<pre><code>"No error" 
checkDevices_slot
SLOT WriteToPort 
Write Request =  "\xA5\x01""c0000\xC9" 
EMIT SendReadData 
</code></pre>
<p dir="auto">This is a normal situation: one request - one response (<code>EMIT SendReadData</code> message).<br />
But often I see the next situation for one cycle:</p>
<pre><code>"No error" 
checkDevices_slot
SLOT WriteToPort 
Write Request =  "\xA5\x01""c0000\xC9" 
EMIT SendReadData 
EMIT SendReadData 
</code></pre>
<p dir="auto">This is a unnormal situation: one request - two responses (2 <code>EMIT SendReadData</code> messages).</p>
<p dir="auto">And I can't to fix it! I used waitForReadyRead() method even with 1sec delay - and the same problem. I even removed all reading functions in slot (like now) - and the same problem. Maybe, it exists because of baudrate = 9600... I don't know.</p>
<p dir="auto">Hope for your help! Thank you in advance!</p>
]]></description><link>https://forum.qt.io/topic/127074/qserialport-readyread-signal-is-emitted-2-times-instead-of-1-time</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 12:34:46 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/127074.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 28 May 2021 07:12:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QSerialPort: readyRead() signal is emitted 2 times instead of 1 time on Fri, 28 May 2021 07:51:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/oboxpoh">@<bdi>oBOXPOH</bdi></a> said in <a href="/post/662050">QSerialPort: readyRead() signal is emitted 2 times instead of 1 time</a>:</p>
<blockquote>
<p dir="auto">What do you advice to do with processing of such situations?</p>
</blockquote>
<p dir="auto"><a href="https://forum.qt.io/topic/117760/qtserialport-problems-with-the-continuous-reading-of-data-from-the-serial-port/2">https://forum.qt.io/topic/117760/qtserialport-problems-with-the-continuous-reading-of-data-from-the-serial-port/2</a></p>
]]></description><link>https://forum.qt.io/post/662053</link><guid isPermaLink="true">https://forum.qt.io/post/662053</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Fri, 28 May 2021 07:51:16 GMT</pubDate></item><item><title><![CDATA[Reply to QSerialPort: readyRead() signal is emitted 2 times instead of 1 time on Fri, 28 May 2021 07:42:28 GMT]]></title><description><![CDATA[<p dir="auto">@J-Hilk said in <a href="/post/662036">QSerialPort: readyRead() signal is emitted 2 times instead of 1 time</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/oboxpoh">@<bdi>oBOXPOH</bdi></a> first of all, do not <code>QThread::msleep(1000);</code> in your slot!</p>
<blockquote>
<p dir="auto">This is a normal situation: one request - one response (EMIT SendReadData message).</p>
</blockquote>
<p dir="auto">thats actually the exception. Normal is: "An unspecified amount of readyRead Signals per request send"</p>
<p dir="auto">with a normal Serialport connection, there is no guarantee that all data is already there, when the signal is emitted. Usually one has some kind of protocol on top of the serial port to fix this issue.</p>
<p dir="auto">You only get a signal, notifying you that there is some data available to fetch, and you have to decide if ist the complete answer yet or not.</p>
</blockquote>
<p dir="auto">I used msleep() method only to recognize the problem, when I get the second signal.</p>
<p dir="auto">I understand, that signal only notifying me that I have some data. And I used waitForReadyRead() method to catch all. But anyway I got the second readyRead() signal without, by the way, response data.</p>
<p dir="auto">What do you advice to do with processing of such situations?</p>
]]></description><link>https://forum.qt.io/post/662050</link><guid isPermaLink="true">https://forum.qt.io/post/662050</guid><dc:creator><![CDATA[oBOXPOH]]></dc:creator><pubDate>Fri, 28 May 2021 07:42:28 GMT</pubDate></item><item><title><![CDATA[Reply to QSerialPort: readyRead() signal is emitted 2 times instead of 1 time on Fri, 28 May 2021 07:18:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/oboxpoh">@<bdi>oBOXPOH</bdi></a> first of all, do not <code>QThread::msleep(1000);</code> in your slot!</p>
<blockquote>
<p dir="auto">This is a normal situation: one request - one response (EMIT SendReadData message).</p>
</blockquote>
<p dir="auto">thats actually the exception. Normal is: "An unspecified amount of readyRead Signals per request send"</p>
<p dir="auto">with a normal Serialport connection, there is no guarantee that all data is already there, when the signal is emitted. Usually one has some kind of protocol on top of the serial port to fix this issue.</p>
<p dir="auto">You only get a signal, notifying you that there is some data available to fetch, and you have to decide if ist the complete answer yet or not.</p>
]]></description><link>https://forum.qt.io/post/662036</link><guid isPermaLink="true">https://forum.qt.io/post/662036</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Fri, 28 May 2021 07:18:19 GMT</pubDate></item><item><title><![CDATA[Reply to QSerialPort: readyRead() signal is emitted 2 times instead of 1 time on Fri, 28 May 2021 07:16:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/oboxpoh">@<bdi>oBOXPOH</bdi></a> said in <a href="/post/662031">QSerialPort: readyRead() signal is emitted 2 times instead of 1 time</a>:</p>
<blockquote>
<p dir="auto">readyRead</p>
</blockquote>
<p dir="auto">There is no guarantee that readyRead will be emitted only once for each write - data can come in several packages. You should also print data you get in slot_ReadInPort() to see whether this is indeed the case.</p>
]]></description><link>https://forum.qt.io/post/662033</link><guid isPermaLink="true">https://forum.qt.io/post/662033</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Fri, 28 May 2021 07:16:26 GMT</pubDate></item></channel></rss>