QSerialDevice

Qt Components

Source (link to git-repo or to original if based on someone elses unmodified work): Add the source-code for this project on opencode.net

13
7.9
Description:

So, announces release: QSerialDevice 2.0

QSerialDevice – cross-platform library for serial devices based on Qt4.

Release 2.0 will be the last for the library QSerialDevice.

Recently the project (2.0 branch) has been accepted into Qt as an addon (renamed to QtSerialPort), therefore, the current Gitorious repository is no longer used, and his development frozen. Ie do not send more here merge requests, etc., his repository works only in r/o mode.

The new repository is now available here (only available to registered developers):

git clone ssh://codereview.qt-project.org:29418/playground/qtserialport.git

More see: http://qt-project.org/wiki/QtSerialPort

In the future, after the stabilization of the code will create a public repository QtSerialPort, which is an addon for Qt (LGPL + commercial).

Version history:
v 0.4.0 (Outdated)
v 0.3.0 (Outdated)
v 0.2.0 (Outdated)
v 0.1.0 (Outdated)
Last changelog:

9 years ago

More changes.

9

bronkopavel

10 years ago

qserialdevice\nativeserialengine_win.cpp(26) : fatal error C1083: Datei (Include) kann nicht ge”ffnet werden: "ddk/ntddser.h": No such file or directory

Report

C

kuzulis

10 years ago

Try to search for header files Visual Studio similar files. Plug them and write me the result.

Report

9

bronkopavel

10 years ago

Hi,

I could see that this header file is in the MinGW installation, MSVC2008 does not have this file?! Any suggestions from your side? Bronko

Report

C

kuzulis

10 years ago

>c:\qserialdevice\src\qserialdevice\nativeserialnotifier.h(8) :"QtCore/private/qwineventnotifier_p.h": No such file or directory

In your SDK is not private file "qwineventnotifier_p.h". I do this do nothing, this is a feature of this version of SDK. Take it from source Qt this file, list the path to it and compile. Other way I can not see ...

Report

C

kuzulis

10 years ago

It should now compile. I updated the repository.
Uploading from the current master branch:
http://gitorious.org/qserialdevice/qserialdevice/archive-tarball/master

Report

9

bronkopavel

10 years ago

This should be OK now, but meanwhile I installed Qt SDK 1.1beta(Qt 7.2) and there is a new issue when compiling your lib with MSVC++: c:\qserialdevice\src\qserialdevice\nativeserialnotifier.h(8) :"QtCore/private/qwineventnotifier_p.h": No such file or directory

Report

C

kuzulis

10 years ago

Check and write me the result.

Report

9

ilpaso

10 years ago

Hi
Does QSerialDevice class manage the XON/XOFF flow control.

What is the code in order to send datas to a device with this flow control?

I've to send datas to a device which sends a XOFF when its buffer is full and a XON when I can restart to transfer the datas.

Thank you

Report

9

ilpaso

10 years ago

Hi,
I'm able to write and read text. I'd like to send an entire binary file.
I read the file with QFile class but I'm not able to use the finctions "write" in order to sent it.

Thank you for the help

Report

C

kuzulis

10 years ago

Hi.

1. Why are you not able to use method: write() ?? Explain!
2. QByteArray is a container for any data. What do you mean by binary data?
3. If you want to use QDataStream - then try to download the current branch library (the master) and use the same Qt sockets. Try it.

PS: I advise you to look at the examples /examples. It sends and receives binary data.

Report

9

ilpaso

10 years ago

thank you Kuzulis for your answer.
Sorry but I understand I'm confused.
For binary file I mean a non text file.

I understand now QByteArray is a container for any data. I'll try to load an entire file and send it over the serial port.

The next questions are:
- If I need a XON/XOFF flow control I've to set the control and does the class do all the work? I've only to send the datas as shown in the examples?

- What do you mean when you write about the QDataStream: "... try to download the current branch library (the master) and use the same Qt sockets...". What is the "current branch library"?

Thank you for the help and sorry again for the confusion.

Report

C

kuzulis

10 years ago

>If I need a XON/XOFF flow control I've to set the control and does the class do all the work? I've only to send the datas as shown in the examples?

Yes, after opening use the method: setFlowControl() and continue to do everything as in the examples (by analogy).

> What is the "current branch library"?

http://gitorious.org/qserialdevice/qserialdevice/archive-tarball/master

Report

9

ilpaso

10 years ago

thank you Kuzulis for your answer.
Now my serial port works with XON/XOFF flow control.
I'm able to send a whole text file but I've some problem with binary file.

For me binary files are files without a char or other encoding.
At the moment I've to read a 32500bits file and send it over serial port.
I wrote something like this:

/////////////////
QFile inFile("image.bin");
if( ! inFile.open( QIODevice::ReadOnly ) )
{
cerr << "Cant find file " << filename << endl;
}

QByteArray block;
block = inFile.readAll();
quint64 r = port->write(block);
if (r == quint64(block.size()))
qDebug() << "Writed: " << r << " bytes";
/////////////////

The program returns "Writed: 32500bytes" but it sends only about 7110.


Maybe I've to use QDatastream but I'm not able to use it. I read some documents and the Qt user guide but I need a little help in order to send the QDataStream over the serial port.

Thank you for your help and sorry for my english.

Report

9

ilpaso

10 years ago

Hi,
I'm able to write and read text. I'd like to send an entire binary file.
I read the file with QFile class but I'm not able to use the finctions "write" in order to sent it.

Thank you for the help

Report

RomanG

10 years ago

Hi there,

first many thanks for your nice work!
I included your code into my project and it worked strait ahead!
In my project I connect a device via an USB Serial Port Chip from FTDI. So nothing special there. Connection works fine data can be exchanged. But now if someone pull out the USB cable, windows (unfortuntely... i rather use linux but as you know bill is everywhere..) dismount the port. This will be detected by the serial enumerator which "forces" me to close the port. Unfortunately as I debuged, this cant be done with your code since you check the port first via isValid(). Am I right? If so, is there a way to fix that problem?

many thanks in advance.

greetings
Roman

Report

RomanG

10 years ago

Hi there,

first many thanks for your nice work!
I included your code into my project and it worked strait ahead!
In my project I connect a device via an USB Serial Port Chip from FTDI. So nothing special there. Connection works fine data can be exchanged. But now if someone pull out the USB cable, windows (unfortuntely... i rather use linux but as you know bill is everywhere..) dismount the port. This will be detected by the serial enumerator which "forces" me to close the port. Unfortunately as I debuged, this cant be done with your code since you check the port first via isValid(). Am I right? If so, is there a way to fix that problem?

many thanks in advance.

greetings
Roman

Report

9

Chief677

10 years ago

Hey,

Thank you for that nice piece of code, I switched from libserial to QextSerialPort and finally to QSerialDevice. But I have a problem. My program works fine on my desktop computer (Ubuntu Lucid 10.04 amd64), but on my notebook (Ubuntu Lucid 10.04 i386) reading from the serial interface doesn't work, but writing data does. I tried raising the timeout but it didn't help. I don't know what else I can try, maybe you know something? I'm using the same USB to RS232 Adapter on both pc's.

Report

9

Chief677

10 years ago

Sry, I have found the problem. Serial settings weren't correctly setuped (before opening and this is not allowed in QSerialDevice) and on the desktop computer it worked, because the serial setting were set by a preceding libary :-) Some bugs are so hard to find ...

Report

sunbin

10 years ago

QSerialDevice: readAll consumming too much time.
I am using QSerialDevice for Stop/Wait(handshaking)communicating, but i found the speed is really slow, only about 10kB/s. So I do a time tracking on my application, finally find the bottleneck: the readAll.

To confirm it, I change a little AbstractSerial's souce code to print the time, here is the result:
AbstractSerial readAll, before read Time: "20:13:593"
AbstractSerial readAll, after read Time: "20:13.796"

So every readAll need a 200ms time delay, for my application, one handshake send 4096 Bytes, so the speed is about 10kB/s.(If I let one handshake send 8192 bytes, some data will lose! I havn't found the way to set the size of AbstractSerial's buffer size.)

So I am asking how to improve the readAll() 's speed?
And, is there a way to see or set AbstractSerial's buffer size?

Here is the testing code changed on the AbstractSerial.cpp :
#ifdef READALL_DEBUG_SUNBIN
qDebug() << "AbstractSerial readAll, before read Time: "
<<QTime::currentTime().toString("hh:mm:ss.zzz");
#endif
// Size is unknown, read incrementally.
for (;;) {
qint64 ret = d->serialEngine->read(d->rxChunkBuffer, ABSTRACTSERIAL_READ_CHUNK_SIZE);

if (ret < 0) {
this->emitStatusString(EReadDataIO);
result.clear();
break;
}
if (ret > 0)
result.append(d->rxChunkBuffer, int(ret));
else
break;
}
#ifdef READALL_DEBUG_SUNBIN
qDebug() << "AbstractSerial readAll, after read Time: "
<<QTime::currentTime().toString("hh:mm:ss.zzz");
#endif
d->emittedReadyRead = false;
return result;

Report

C

kuzulis

10 years ago

Nothing will be lost!
Take a crossover cable and connect them to ports on your computer. Take the examples / writer and / sreader and check.
Can send bytes as you want (at least 8192, at least 16000, at least 100000, and etc) and they will be read.
Can change charIntervalTimeout experimentally for better communication.

What is the actual problem?
What is "Stop/Wait(handshaking)communicating" ?

Report

sunbin

10 years ago

Oh, I need more try.
My question is: why readAll()'s reading action is so slow, it cause 200ms to finish, no matter it is reading 4 bytes ACK message, or it is reading 4096 bytes data message?

And I am not sure about how big the buffer is? Both hardware and software need buffer, an overflow may come out. I need a check tomorrow, cause yesteday I test the COM through Virtual Serial Port, the Virtual Port make a transmit through Tcp/IP, this may cause problem.

So, thank you very much.

The Stop/wait protocal is: when sender sends out a bunch of data, it wait for reciever's ACK message, then sends again, this is the most simple way of flow control, see “Computer Networks” by Andrew S.Tanenbaum。 I use this Stop/Wait way because I found if I am sending too fast, overflow of buffer comes out, and the Xon/Xoff does not have much effect.

Report

C

kuzulis

10 years ago

I do not know why it's so slow.
1. Maybe you have an error (inaccuracy) in the time dimension, because QTime gives an error (inaccuracy) + / - 50-70 ms.
2. Maybe at the reception of data affects charIntervalTimeout, which by default is 50 ms. Try to reduce it.
3. In what operating system you are doing the test?

Report

sunbin

10 years ago

Solved, yet another question.

It is the "charIntervalTimeout", I used to thought it was like the Modbus protocal's Timeout argment(i.e. play a role to distinguish frame from frame by not recieving data for 10ms), cause I do not use the Modbus way, I didn't care about this charIntervalTimeout, and set it to 100ms. By the way, the QTime's accuracy is good.

Another question, if I set the BautRate to higher than 115200(e.g. 256000), it will throw a set error. Why?

Thank you very much.

Report

C

kuzulis

10 years ago

> Another question, if I set the BautRate to higher than 115200(e.g. 256000), it will throw a set error. Why?

I do not know. Test yourself. And if you can find the cause - then let me know.

Report

sunbin

10 years ago

After see the library's code, finally I find it's the PC hardware's(16C550 chip, maybe) limitation, 115200 at largest which I didn't know before.

Thank you for answers and your good work, I found it more friendly to use compare to the qextserialport lib.

Report

9 years ago

More changes.

12345678910
13
product-maker nadir22 Nov 28 2012 9 excellent
product-maker qstring Jul 25 2012 9 excellent
product-maker agnitsarkar Mar 15 2012 9 excellent
product-maker EvilTosha Jan 21 2012 9 excellent
product-maker peer Dec 30 2011 9 excellent
product-maker michaudg Jun 29 2011 9 excellent
product-maker woodywoodpecker Jun 25 2011 9 excellent
product-maker Krozac Apr 25 2011 9 excellent
product-maker bronkopavel Mar 01 2011 9 excellent
product-maker torsen Feb 03 2011 9 excellent
product-maker ilpaso Nov 30 2010 9 excellent
product-maker Chief677 Sep 28 2010 9 excellent
product-maker lit-uriy Sep 21 2010 9 excellent
Be the first to comment
nadir22
Mar 21 2012
iframe777
Mar 17 2012
peer
Feb 01 2012
Krozac
Sep 20 2011
wcai
Sep 05 2011
michaudg
Jun 29 2011
MaX-MoD
Mar 02 2011
lit-uriy
Jan 06 2011
ilpaso
Nov 30 2010
bronkopavel
Nov 14 2010
mariuszekpl
Oct 31 2010
NickGaens
Apr 28 2010
kostya2vntu
Mar 19 2010
File (click to download) Version Description Downloads Date Filesize DL OCS-Install MD5SUM
*Needs pling-store or ocs-url to install things
Pling
0 Affiliates
Details
license
version
2.0
updated Mar 15 2012
added Sep 15 2009
downloads 24h
0
mediaviews 24h 0
pageviews 24h 5
System Tags