<?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[Missing data in qSerialPort]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I have written a very simple class to check serial port communication over Qt.</p>
<p dir="auto">This is actually serial port communication via the USB port.  I am talking to a PIC based microcontroller.  I read all the serial ports, identify the one to which the microcontroller is attached;  Then I send 0xE0 repeatedly and read all the data sent over the serial port with a readAll().</p>
<p dir="auto">When I send the 0xE0 over the serial port using "realterm serial port communication program", the microcontroller sends data for nearly a second, the status of all 15 I/O ports.</p>
<p dir="auto">When I use the qserialport I hardly get 10 bytes and that too, not every time, also it does not take 1 second to read unlike in the realterm application!<br />
@#include &lt;QCoreApplication&gt;<br />
#include &lt;QDebug&gt;<br />
#include &lt;QSerialPort&gt;<br />
#include &lt;QSerialPortInfo&gt;<br />
#include &lt;QIODevice&gt;</p>
<p dir="auto">int main(int argc, char *argv[])<br />
{<br />
QCoreApplication a(argc, argv);<br />
QString portID;</p>
<pre><code>qDebug() &lt;&lt; "Number of serial ports:" &lt;&lt; QSerialPortInfo::availablePorts().count();

foreach (const QSerialPortInfo &amp;serialPortInfo, QSerialPortInfo::availablePorts()) {

    qDebug() &lt;&lt; "\nPort:" &lt;&lt; serialPortInfo.portName();
    if (serialPortInfo.description() == "Communications Port") portID = serialPortInfo.portName();

}
printf ("Opening Port %s\n",qPrintable(portID));
if (portID.size() &gt; 1)
{
    //could do  reinterpret_cast and have const unsigned char
    unsigned char temp_char = 0xE0;
    QSerialPort embed;
    embed.setPortName(portID);
    embed.setBaudRate(QSerialPort::Baud115200);
    embed.setDataBits(QSerialPort::Data8);
    embed.setParity(QSerialPort::NoParity);
    embed.setStopBits(QSerialPort::OneStop);
    embed.open(QIODevice::ReadWrite);
    embed.write(reinterpret_cast&lt;const char*&gt;(&amp;temp_char),1);

    int numRead = 0,numReadTotal = 0;
    QByteArray buffer;

    for (int i=1; i&lt;=20;i++) {
        QCoreApplication::processEvents( QEventLoop::AllEvents );
        buffer = embed.readAll();
        numRead  = buffer.size();
        printf ("%d Reading Port Data count %d\n",i, numRead);
        for (int j = 0; j &lt; numRead; j++)
            printf ("Data %x, count %d\n",buffer.at(j),j+1);
        // Do whatever with the array

        numReadTotal += numRead;
        if (numRead == 0 &amp;&amp; (numReadTotal &gt; 100))
            break;
        embed.write(reinterpret_cast&lt;const char*&gt;(&amp;temp_char));
    }
    embed.close();
}
else printf("Port Not Found!\n");

return 0;
</code></pre>
<p dir="auto">}@<br />
Any suggestions on where to look for a bug?</p>
]]></description><link>https://forum.qt.io/topic/36904/missing-data-in-qserialport</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 17:17:35 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/36904.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 22 Jan 2014 11:02:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Missing data in qSerialPort on Thu, 23 Jan 2014 08:14:46 GMT]]></title><description><![CDATA[<p dir="auto">I thought waitforreadyread() made the call synchronous?  I thought my approach was asynchronous.  I will have to rethink my approach.</p>
<p dir="auto">I put a loop of 20 because for every 0XE0 sent to the microprocessor, it returns upto about 3000 bytes, the status of 15 input/output ports.</p>
<p dir="auto">Thanks for the input, I will look into signal/slot for the communication.</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://forum.qt.io/post/211934</link><guid isPermaLink="true">https://forum.qt.io/post/211934</guid><dc:creator><![CDATA[kpks]]></dc:creator><pubDate>Thu, 23 Jan 2014 08:14:46 GMT</pubDate></item><item><title><![CDATA[Reply to Missing data in qSerialPort on Thu, 23 Jan 2014 07:18:25 GMT]]></title><description><![CDATA[<p dir="auto">bq. I get about 10 bytes through qt :(</p>
<p dir="auto">Because this is wrong:</p>
<p dir="auto">@<br />
for (int i=1; i&lt;=20;i++) {<br />
...<br />
}<br />
@</p>
<p dir="auto">Why do you think that for 20 iterations the device will accept more than 10 bytes?</p>
<p dir="auto">The serial port - very slow device in comparison with qt event-loop. Thus your 20 iterations will end before the device will receive all data.</p>
<p dir="auto">You need to use the forever loop with the method of waiting of data waitForReadyRead() and the method of getting number of available data bytesAvailable() instead of 20 iterations.</p>
<p dir="auto">Besides, the waitForReadyRead() method has an bugs. These bugs are fixed in the following release of Qt 5.2.1 (but you can download the "release" branch from Git and manually rebuild and reinstall the QtSerialPort).</p>
<p dir="auto">And last, very important council: use asynchronous approach with signals/slots. This decision is better because doesn't contain bugs (at least doesn't contain critical errors). See QtSerialPort's examples, read documentation.</p>
]]></description><link>https://forum.qt.io/post/211929</link><guid isPermaLink="true">https://forum.qt.io/post/211929</guid><dc:creator><![CDATA[kuzulis]]></dc:creator><pubDate>Thu, 23 Jan 2014 07:18:25 GMT</pubDate></item><item><title><![CDATA[Reply to Missing data in qSerialPort on Thu, 23 Jan 2014 04:20:41 GMT]]></title><description><![CDATA[<p dir="auto">This what I get from the realterm:<br />
E0F960880090179D10A000877F880190129D0CA00088009016A000877F901E9C7D87<br />
7F88009024A000877F901D9C71877F88009C6BA00088009010A000877F88009C61A00088009020A0<br />
01877F90249C59877F88009C55A001880090149C51877F88009C4EA00188009018A001877F90229C<br />
48877F88009C45A001877F901C9C42877F88009C40A00188009012A002877F901A9C3CA002880090<br />
23A002877F90229C38877F88009C36A00288009.........................9C1B</p>
<p dir="auto">I get about 10 bytes through qt :(</p>
]]></description><link>https://forum.qt.io/post/211926</link><guid isPermaLink="true">https://forum.qt.io/post/211926</guid><dc:creator><![CDATA[kpks]]></dc:creator><pubDate>Thu, 23 Jan 2014 04:20:41 GMT</pubDate></item><item><title><![CDATA[Reply to Missing data in qSerialPort on Wed, 22 Jan 2014 12:25:05 GMT]]></title><description><![CDATA[<p dir="auto">This is wrong init sequence:<br />
@<br />
embed.setPortName(portID);<br />
embed.setBaudRate(QSerialPort::Baud115200);<br />
embed.setDataBits(QSerialPort::Data8);<br />
embed.setParity(QSerialPort::NoParity);<br />
embed.setStopBits(QSerialPort::OneStop);<br />
embed.open(QIODevice::ReadWrite);<br />
@</p>
<p dir="auto">should be:<br />
@<br />
embed.setPortName(portID);<br />
embed.open(QIODevice::ReadWrite);<br />
embed.setBaudRate(QSerialPort::Baud115200);<br />
embed.setDataBits(QSerialPort::Data8);<br />
embed.setParity(QSerialPort::NoParity);<br />
embed.setStopBits(QSerialPort::OneStop);<br />
@</p>
<p dir="auto">Besides, it is strongly recommended to check returned values of the methods: open() and setXXX().</p>
<p dir="auto">Also please provide an log out of expected data and real received (your printf) data.</p>
]]></description><link>https://forum.qt.io/post/211813</link><guid isPermaLink="true">https://forum.qt.io/post/211813</guid><dc:creator><![CDATA[kuzulis]]></dc:creator><pubDate>Wed, 22 Jan 2014 12:25:05 GMT</pubDate></item></channel></rss>