<?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[Serialport Timeout Error]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I created an application to send command to a printer. But after writing, some times it shows  QSerialPort::SerialPortError(TimeoutError).</p>
<pre><code>while(1)
    {
        u_int8_t u_arr_n8ArraytoSend[]={0x1b,0x4a,0};
        QTextStream textstream(&amp;file);
        u_arr_n8ArraytoSend[2]=20;
        u_int8_t u_nRxBytes;
        u_int8_t u_n8BytesReturn;
        QThread::sleep(0.5);
        u_nRxBytes=serial-&gt;write((char *)u_arr_n8ArraytoSend,3);
        u_n8BytesReturn=serial-&gt;waitForBytesWritten(1000);
        qDebug()&lt;&lt;"u_n8BytesReturn"&lt;&lt;u_n8BytesReturn;
        if(WRITESUCCESS==u_n8BytesReturn)
        {
           textstream&lt;&lt;"Write Success"&lt;&lt;u_n8BytesReturn&lt;&lt;"\n";
           u_int8_t u_arr_n8ArraytoSend2[]={0x1b,0x69};
           QThread::sleep(0.5);
           u_nRxBytes=serial-&gt;write((char *)u_arr_n8ArraytoSend2,2);
           u_n8BytesReturn=serial-&gt;waitForBytesWritten(1000);
           if(WRITESUCCESS==u_n8BytesReturn)
           {
              textstream&lt;&lt;"Write Success"&lt;&lt;u_n8BytesReturn&lt;&lt;"\n";
              ncount++;

              qDebug()&lt;&lt;"ncount"&lt;&lt;ncount;
           }
           else
           {
               qDebug() &lt;&lt;"error is"&lt;&lt;serial-&gt;error();
               textstream&lt;&lt;"Write Fail"&lt;&lt;u_n8BytesReturn&lt;&lt;"\n";
           }

        }
        else
        {
            qDebug() &lt;&lt;"error is"&lt;&lt;serial-&gt;error();
            textstream&lt;&lt;"Write Fail"&lt;&lt;u_n8BytesReturn&lt;&lt;"\n";
        }

       QThread::sleep(10);
      textstream&lt;&lt;"count:"&lt;&lt;ncount&lt;&lt;"\n";

    }
</code></pre>
<p dir="auto">This is the code i wrote. Is there any problem with this code??</p>
<p dir="auto">Thanks.</p>
]]></description><link>https://forum.qt.io/topic/98529/serialport-timeout-error</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 20:27:17 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/98529.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 15 Jan 2019 05:28:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Serialport Timeout Error on Wed, 16 Jan 2019 18:11:54 GMT]]></title><description><![CDATA[<p dir="auto">You should rethink your code globally.<br />
you can't use QThread::sleep(0.5) out of a QThread.<br />
Probably QThread::sleep(0.5) stops the application and the serial buffers.<br />
Please use QTimer if you have to send / receive continuosly.</p>
]]></description><link>https://forum.qt.io/post/505253</link><guid isPermaLink="true">https://forum.qt.io/post/505253</guid><dc:creator><![CDATA[mrdebug]]></dc:creator><pubDate>Wed, 16 Jan 2019 18:11:54 GMT</pubDate></item><item><title><![CDATA[Reply to Serialport Timeout Error on Wed, 16 Jan 2019 03:35:25 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/gojir4">@<bdi>Gojir4</bdi></a> ,<br />
Thanks for your response.  I  changed my code by writing qthread::sleep(15). again error happens.</p>
]]></description><link>https://forum.qt.io/post/504975</link><guid isPermaLink="true">https://forum.qt.io/post/504975</guid><dc:creator><![CDATA[QTlearner90]]></dc:creator><pubDate>Wed, 16 Jan 2019 03:35:25 GMT</pubDate></item><item><title><![CDATA[Reply to Serialport Timeout Error on Tue, 15 Jan 2019 15:45:20 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">QSerialPort::SerialPortError(TimeoutError)</p>
</blockquote>
<p dir="auto">This means that the WAIT_TIMEOUT error occurred, if we say about windows (it happens on system WaitForSingleObject function); or when the system poll() function fails with 0 code, if we say about *nix. It comes from the driver/hardware itself... So, check our HW.</p>
]]></description><link>https://forum.qt.io/post/504887</link><guid isPermaLink="true">https://forum.qt.io/post/504887</guid><dc:creator><![CDATA[kuzulis]]></dc:creator><pubDate>Tue, 15 Jan 2019 15:45:20 GMT</pubDate></item><item><title><![CDATA[Reply to Serialport Timeout Error on Tue, 15 Jan 2019 14:35:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qtlearner90">@<bdi>QTlearner90</bdi></a></p>
<p dir="auto">You are right, QThread::sleep is in second, not in milliseconds. So 10 seconds is far enough to process the command.</p>
<p dir="auto">How do you know the printer has received and understood the command ?</p>
]]></description><link>https://forum.qt.io/post/504873</link><guid isPermaLink="true">https://forum.qt.io/post/504873</guid><dc:creator><![CDATA[Gojir4]]></dc:creator><pubDate>Tue, 15 Jan 2019 14:35:03 GMT</pubDate></item><item><title><![CDATA[Reply to Serialport Timeout Error on Tue, 15 Jan 2019 13:23:48 GMT]]></title><description><![CDATA[<p dir="auto">It seems source code written by a firmware developer instead of a software developer.<br />
Please don't use things like<br />
while(1)<br />
or<br />
QThread::sleep(0.5)<br />
if you aren't in a real thread.</p>
]]></description><link>https://forum.qt.io/post/504849</link><guid isPermaLink="true">https://forum.qt.io/post/504849</guid><dc:creator><![CDATA[mrdebug]]></dc:creator><pubDate>Tue, 15 Jan 2019 13:23:48 GMT</pubDate></item><item><title><![CDATA[Reply to Serialport Timeout Error on Tue, 15 Jan 2019 11:16:22 GMT]]></title><description><![CDATA[<p dir="auto">hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/gojir4">@<bdi>Gojir4</bdi></a> ,</p>
<pre><code>                For checking printers life, i wrote all these commands in    while loop. In normal operation i am giving  QThread::sleep(15) sec . But that time also this error happened.
</code></pre>
]]></description><link>https://forum.qt.io/post/504825</link><guid isPermaLink="true">https://forum.qt.io/post/504825</guid><dc:creator><![CDATA[QTlearner90]]></dc:creator><pubDate>Tue, 15 Jan 2019 11:16:22 GMT</pubDate></item><item><title><![CDATA[Reply to Serialport Timeout Error on Tue, 15 Jan 2019 11:03:05 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/qtlearner90">@<bdi>QTlearner90</bdi></a>,</p>
<p dir="auto">First question, why sending the command in a while loop ? what are you trying to achieve exactly ?</p>
<p dir="auto">Here is the possible causes I can see:</p>
<ol>
<li>Maybe the delay between the commands is too short (about 10ms). The printer may receive a command when the processing of the previous one is not terminated. Or having his serial buffer full because commands are coming too fast.</li>
<li>The printer probably send an acknowledge to indicate the command has been received and processed correctly. Reading and checking this acknowledge could help to synchronize correctly the communication. Or at least clearing the output buffer of the printer.</li>
</ol>
<p dir="auto">And another thing, <code>QThread::sleep(0.5);</code>  will be implicitly converted to <code>QThread::sleep(0)</code> by the compiler as this function does not support real number, only unsigned long.</p>
]]></description><link>https://forum.qt.io/post/504821</link><guid isPermaLink="true">https://forum.qt.io/post/504821</guid><dc:creator><![CDATA[Gojir4]]></dc:creator><pubDate>Tue, 15 Jan 2019 11:03:05 GMT</pubDate></item></channel></rss>