
QSerialDevice
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
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)
9 years ago
More changes.
9 years ago
More changes.
bronkopavel
10 years ago
Report
kuzulis
10 years ago
Report
bronkopavel
10 years ago
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
kuzulis
10 years ago
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
kuzulis
10 years ago
Uploading from the current master branch:
http://gitorious.org/qserialdevice/qserialdevice/archive-tarball/master
Report
bronkopavel
10 years ago
Report
kuzulis
10 years ago
Report
ilpaso
10 years ago
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
ilpaso
10 years ago
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
kuzulis
10 years ago
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
ilpaso
10 years ago
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
kuzulis
10 years ago
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
ilpaso
10 years ago
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
ilpaso
10 years ago
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
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
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
Chief677
10 years ago
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
Chief677
10 years ago
Report
sunbin
10 years ago
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
kuzulis
10 years ago
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
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
kuzulis
10 years ago
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
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
kuzulis
10 years ago
I do not know. Test yourself. And if you can find the cause - then let me know.
Report
sunbin
10 years ago
Thank you for answers and your good work, I found it more friendly to use compare to the qextserialport lib.
Report