lemanhtrung / qextserialport

Automatically exported from code.google.com/p/qextserialport
Other
0 stars 0 forks source link

writeData function in Posix sistem "blocks" the signals #74

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using a Ubuntu 2.6.32-24 kernel, Qt4.6 and Eclipse.

In my project I'm using the QExtSerialPort library: in a class I have a QTimer 
and a QextSerialPort pointer, every second the timer emits the signal timeOut() 
and the slot write() will write on the port.

When I run the project the timer emits only once signal after the first second. 
When I change the window focused the timer emits other signal and soon. When I 
comment the lines used to write to the serial port the timer work normally. I 
think the problem is in the line 954 (int retVal = ::write(fd, data, maxSize);) 
in the file posix_qextserialport.cpp.

If I understand correctly this function is in the fcntl.h header, but I can't 
open/modify it. You know, isn't good idea modify the system's files...

Well, I hope you can understand my English and works fine with this 
information, if you need some help I'm here.

Tanks for the library...

PS: now I'm going to write some code to send you where the problem occurs.

Original issue reported on code.google.com by robypomper on 25 Aug 2010 at 8:41

GoogleCodeExporter commented 9 years ago
Here the project where you can test the problem...

For test you have to run 2 time: 1st time with the line SerialProblem.cpp:40 
not commented and the second time try to comment it. At first run the line 
"write()" will be write only when you change the focused window, at second time 
the same line will be write every second.

In ubuntu the package who provide the file fcntl.h is libc6-dev and my version 
is 2.11.1-0ubuntu7.2 maybe the problem is there.

The project was created with Eclipse Helios.

Original comment by robypomper on 25 Aug 2010 at 9:11

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Very strange.

I have downloaded your code compiled and tried.

My FTDI cable was plugged to my Friendlyarm board which had a linux console 
output on it's  port.

At the first try I hade noticed the high CPU usage, and sometimes the the timer 
shooted again. 

I have put to the output the number of bytes written:

qDebug() <<_port->write("$>9000RQCE#");

And I seen that the write was successful, so the code is stucking somewhere 
else.  

After that I have connected the readyReadSignal, and read the incoming data in 
it the high CPU usage had left, and the timer interval get's back to normal. 

As workaround you should use QextSerialPort::Polling mode in the opening if you 
do not want to use the reading.

The problem's root is the following:

In event driven mode the QSocketNotifier emits activated(int) signal always 
when a data is available on the port. Since in your example there is nothing 
what should read the data it locks the main loop.

This kind of operation confronts with the QIODevice's readyRead signal's 
description:

This signal is emitted once every time new data is available for reading from 
the device. It will only be emitted again once new data is available, such as 
when a new payload of network data has arrived on your network socket, or when 
a new block of data has been appended to your device.

Original comment by martonmi...@gmail.com on 30 Aug 2010 at 3:29

GoogleCodeExporter commented 9 years ago
Well I have tried to patch the problem, but it seems to be impossible to do it 
in this way.
The QSocketNotifier emits always signals if there is unreaded data on the port. 
I have written a slot to check that the available bytes number is changed. Now 
it works, but it eats all the CPU time. 

Original comment by martonmi...@gmail.com on 30 Aug 2010 at 3:46

GoogleCodeExporter commented 9 years ago
Thanks

Original comment by dbzhang...@gmail.com on 16 Mar 2012 at 8:17