May 3, 2011

Luca Luca
Ant Farmer
637 posts

QExtSerialPort && waitForReadyRead

 

Hi all,
I’m communicating with an RS-485 device via QExtSerialPort .
I’d like to have a working waitForReadyRead in my project but it isn’t supported by QExtSerialPort.

Do someone know if it’s possible to implement a waitForReadyRead using QExtSerialPort ?

14 replies

May 3, 2011

ZapB ZapB
Ant Farmer
1424 posts

I think we had this issue too and we hacked in a basic support for it using QSocketNotifier’s on the Linux side of things. I can’t recall if we got it working on Windows – I would have to check.

Are you using the very latest version of qextserialport [code.google.com]? If that still doesn’t contain support fo rthis I can see if I can extract the necessary parts form our internal copy and make them available upstream. In fact, this has been on my todo list for ages but never very far up it ;-)

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

May 3, 2011

Luca Luca
Ant Farmer
637 posts

I think I’m not using the last alpha version.
I’ll try with it and I’ll tell you.

Thanks.

May 3, 2011

Luca Luca
Ant Farmer
637 posts

I confirm you.
The 1.2-alpha version has the same problem.

May 3, 2011

stuk stuk
Ant Farmer
561 posts

Have you look this project? https://gitorious.org/qserialdevice [gitorious.org]

May 3, 2011

Andre Andre
Robot Herder
6393 posts

Would spinning an eventloop while waiting for the signal be a solution for you? Or just use QxtSignalWaiter?

May 3, 2011

Luca Luca
Ant Farmer
637 posts
stuk wrote:
Have you look this project? https://gitorious.org/qserialdevice [gitorious.org]

I didn’t know this, I’ll try.

May 3, 2011

Luca Luca
Ant Farmer
637 posts
Andre wrote:
Would spinning an eventloop while waiting for the signal be a solution for you? Or just use QxtSignalWaiter?

I have the function to read from serial port in a second thread so form me there isn’t the problem of blocking event loop. I’d like to do this:

  1. serialPort->write("123456\r\n");
  2. serialPort->waitForReadyRead(10000);
  3. int num_byte =serialPort->bytesAvailable();
  4. if(num_byte>=10)
  5. {
  6.     qDebug() << "Num BYTE: " << num_byte;
  7.     qDebug() << serialPort->read(num_byte);
  8. }

May 3, 2011

Andre Andre
Robot Herder
6393 posts

It was mend as a work-around for the problem that waitForReadyRead doesn’t work for you. I understand that it is not ideal, but it may just do the trick.

May 3, 2011

Luca Luca
Ant Farmer
637 posts
Andre wrote:
It was mend as a work-around for the problem that waitForReadyRead doesn’t work for you. I understand that it is not ideal, but it may just do the trick.

So sorry, I didn’t understand you question.

As work-around I’ll use this:

  1. serialPort->write("123456\r\n");
  2. while(1)
  3. {
  4.   int num_byte =serialPort->bytesAvailable();
  5.   if(num_byte>=10)
  6.   {
  7.       qDebug() << "Num BYTE: " << num_byte;
  8.       qDebug() << serialPort->read(num_byte);
  9.       break;
  10.   }
  11. }

or something similar.

May 3, 2011

Luca Luca
Ant Farmer
637 posts
stuk wrote:
Have you look this project? https://gitorious.org/qserialdevice [gitorious.org]

Thanks, It seems to works. I must do some tests but it goes in the right way.

May 3, 2011

Andre Andre
Robot Herder
6393 posts

As work-around I’ll use this:
  1. serialPort->write("123456\r\n");
  2. while(1)
  3. {
  4.   int num_byte =serialPort->bytesAvailable();
  5.   if(num_byte>=10)
  6.   {
  7.       qDebug() << "Num BYTE: " << num_byte;
  8.       qDebug() << serialPort->read(num_byte);
  9.       break;
  10.   }
  11. }

or something similar.

I would not do that. That will keep the eventloop occupied, and that in turn may interfere with the working of the serial port you’re interested in. Not a good plan.

How about something like this:

  1. QxtSignalWaiter waiter(serialPort, SIGNAL(readyRead());
  2. serialPort->write("123456\r\n");
  3. if (waiter.wait(10000)) {
  4.     int num_byte =serialPort->bytesAvailable();
  5.     if(num_byte>=10)
  6.     {
  7.          qDebug() << "Num BYTE: " << num_byte;
  8.          qDebug() << serialPort->read(num_byte);
  9.     }
  10. } else {
  11.      //timeout waiting...
  12. }

Edit: if another serial port implementation works better, then that is obviously a much better solution than messing around with hacks like QxtSignalWaiter.

May 3, 2011

Luca Luca
Ant Farmer
637 posts

Thanks Andre, I never used QxtSignalWaiter but it seems very useful .

May 3, 2011

Andre Andre
Robot Herder
6393 posts

It is, but it does have its limitations. This is important to realize:

Note: QxtSignalWaiter is not reentrant. In particular, only one QxtSignalWaiter object per thread can be safely waiting at a time. If a second QxtSignalWaiter is used while the first is waiting, the first will not return until the second has timed out or successfully caught its signal.

Please be aware of those before using it. Also, often the use can be worked around, and if you can, that is often the better approach.

May 3, 2011

stuk stuk
Ant Farmer
561 posts

This project is not very popular but for me is better than Qextserialport.

Luca wrote:
stuk wrote:
Have you look this project? https://gitorious.org/qserialdevice [gitorious.org]

Thanks, It seems to works. I must do some tests but it goes in the right way.

 
  ‹‹ Creating and adding a static library      QExtSerialPort port->write Problem ››

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