PDA

View Full Version : Definitive serial library



Marco Trapanese
22nd May 2009, 11:26
Hello,

I apologize if my English is not so good.
I use QT4 to develop applications for Windows and Linux, in both desktop and embedded environments.

I need use a lot of serial connections (often I have 4-5 serial devices connected) so I'm looking for a *reliable* and complete serial library. I don't understand why QT4 doesn't support serial communication natively, I think they are used a lot in embedded applications.

Anyway, I'm playing with the Qextserial but it seems to me a bit buggy and it has many limitations.

Please, may you suggest me a complete serial library that:

* works under Windows and Linux,
* uses signals to tell when data is ready to be read (with buffer thresholds)
* has a working lineread() method
* enumerates available ports under both Windows and Linux

I'm asking too much? What do you embedded programmers use?

Thanks

Marco Trapanese
Italy

kuzulis
22nd May 2009, 13:46
See this topic:
http://www.qtcentre.org/forum/f-qt-programming-2/t-qiodevicebytesavaiable-error-value-21168.html

Try the library.
Add to the library all that you want.

:)



PS: but there is a bug.

Example download: http://www.qtcentre.org/forum/attachment.php?attachmentid=3286&d=1242923390

PaceyIV
22nd May 2009, 22:55
Marco Trapanese asks for signal when there is data available. In your code there isn't this features.

See this topic: http://www.qtcentre.org/forum/f-qt-programming-2/t-qextserialport-with-qtimer-approch-for-reading-21063.html

In the last post there is my class that use QextSerialPort. It implements 2 thread with the signal "dataReceived": it transports the byte available at the serial port. I also made a basic HyperTerminal to test it (It shows ad transmits data in Hexadecimal).

* has a working lineread() method

I don't implement this method: you can add this!

* enumerates available ports under both Windows and Linux

I don't know how to implement this features. In Linux I think I can scan for ttyS* file in /dev/ and maybe also ttyUSB*. I windows I don't know.


Bye

PaceyIV
23rd May 2009, 18:56
I add this method to query available ports name, on both Windows and GNU\Linux



#ifdef _TTY_POSIX_
#include <QDir>
#endif


const int MAX_COM_PORT = 20;

// Query available SerialPort name
QStringList MySerialPort::availablePortsName()
{
QextSerialPort testPort;
testPort.setBaudRate(BAUD115200);
testPort.setFlowControl(FLOW_OFF);
testPort.setParity(PAR_NONE);
testPort.setDataBits(DATA_8);
testPort.setStopBits(STOP_1);

QStringList portsName;
QString testPortName;

#ifdef _TTY_WIN_
for (i=1; i<MAX_COM_PORT; i++)
{
testPortName = QString("COM%1").arg(i)
testPort.setPortName(testPortName);
if (testPort.open(QIODevice::ReadWrite))
{
portsName.append(testPortName);
testPort.close();
}

}
#else // _TTY_POSIX_
QDir dir("/dev");
QStringList filters;
filters << "ttyS*" << "ttyUSB*";
dir.setNameFilters(filters);
dir.setFilter(QDir::Files | QDir::System);
QFileInfoList list = dir.entryInfoList();
for (int i=0; i< list.size(); i++)
{
portsName.append(list.at(i).canonicalFilePath ());
}
#endif

return portsName;
}

Marco Trapanese
24th May 2009, 10:13
Thank you very much PaceyIV, I'll play with you class!
It's a pity that QT4 doesn't have a built-in serial class, I can't understand why.

In this way, everybody should reinvent the wheel... And there are many people (like me) who aren't so skilled to implement the library themselves.

Marco

wysota
24th May 2009, 11:49
There is a big chance a serial class from Qt Extended will make it into desktop Qt.

http://doc.qtsoftware.com/qtextended4.4/qserialiodevice.html
http://doc.qtsoftware.com/qtextended4.4/qserialport.html

Teuniz
25th May 2009, 17:01
I use the code at http://www.teuniz.net/RS-232/

It does not use signals but it does work with Linux and windows.