May 5, 2012

qxoz qxoz
Mad Scientist
1079 posts

Experience with serial interface

 

Hi everyone!
At the moment I am working with a project-intensive uses a serial interface. The data flow is three request-response pairs per second.
I tried to use the qextserialport [code.google.com]
and QtSerialPort [qt-project.org]
for Qt4. As it turned out QtSerialPort easier and more convenient to use, but there is one problem.Sometimes, after receiving some data, the software freezes, and not only software but also the entire operating system. Only hard reset helps.Has anyone encountered this problem?
If not, can some body show me a right way how to work with a serial interface in Qt, for intensive data transferring.
Example from QtSerialPort “terminal” also freezes.

7 replies

May 5, 2012

koahnig koahnig
Gene Splicer
2905 posts

Thanks for sharing your experience when using the alternative implementations of serial interfaces.
However, it would be good to add also some additional information on OS, compilers and RS settings.

May 5, 2012

qxoz qxoz
Mad Scientist
1079 posts

Version of QtSDK: 1.2
OS: Windows7
Compiler: MinGW from QtSDK
RS: 9600bps, 8bit, 1 stop, no parity

May 5, 2012

qxoz qxoz
Mad Scientist
1079 posts

Right now i downloaded last version of qextserialport. I’ll try it soon, and will write here about results.

May 5, 2012

kuzulis kuzulis
Robot Herder
362 posts

2 qxoz,

Give a detailed description of the test with a QtSerialPort, but rather himself a test project (source code).

Try do read/write to port without displaying the results to the GUI.

For example, instead of:

  1. textEdit->append(port->readAll);

do:

  1. QByteArray data = port->readAll();
  2. data = data;

Maybe it’s GUI does not have time to handle request/response,
the idea understand?

May 5, 2012

qxoz qxoz
Mad Scientist
1079 posts

2 kuzulis
Yes i try that. Without GUI result is same.
Open port code:

  1. void RegisterForm::openSerialPort()
  2. {
  3.     SettingsDialog::Settings p;
  4.     p.rate = 9600;
  5.     p.parity = SerialPort::NoParity;
  6.     p.flowControl = SerialPort::NoFlowControl;
  7.     p.dataBits = SerialPort::Data8;
  8.     p.stopBits = SerialPort::OneStop;
  9.     p.name = "COM4";
  10.  
  11.     serial->setPort(p.name);
  12.     if(serial->isOpen())serial->close();
  13.     if (serial->open(QIODevice::ReadWrite)) {
  14.         if (serial->setRate(p.rate)
  15.                 && serial->setDataBits(p.dataBits)
  16.                 && serial->setParity(p.parity)
  17.                 && serial->setStopBits(p.stopBits)
  18.                 && serial->setFlowControl(p.flowControl)) {
  19.  
  20.         } else {
  21.             serial->close();
  22.  
  23.             QMessageBox::critical(this, tr("Error"),
  24.                                   tr("Can't configure the serial port: %1,\n"
  25.                                      "error code: %2")
  26.                                   .arg(p.name).arg(serial->error()));
  27.  
  28.         }
  29.     } else {
  30.         QMessageBox::critical(this, tr("Error"),
  31.                               tr("Can't opened the serial port: %1,\n"
  32.                                  "error code: %2")
  33.                               .arg(p.name).arg(serial->error()));
  34.  
  35.     }
  36. }

Signal connection:
  1. connect(serial, SIGNAL(readyRead()), this, SLOT(readData()));

data read action:

  1. void RegisterForm::readData()
  2. {
  3.      readBytes.append(serial->readAll());
  4.     //some action...
  5. }

May 10, 2012

kuzulis kuzulis
Robot Herder
362 posts

Ok. Try now the new QtSerialPort snapshot.
There is something that has been fixed in terms of CPU usage and operations of I / O.

May 22, 2012

qxoz qxoz
Mad Scientist
1079 posts

Hi kuzulis!
I try the last snapshot of QtSerialPort, and for now not detect any freezing.

 
  ‹‹ Link GSL into Qt Creator      Trouble building QtMock in visual studio, linking errors ››

You must log in to post a reply. Not a member yet? Register here!