QExtSerialPort && waitForReadyRead
-
-
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":http://code.google.com/p/qextserialport/? 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 ;-)
-
Have you look this project? "https://gitorious.org/qserialdevice":https://gitorious.org/qserialdevice
-
[quote author="stuk" date="1304425688"]Have you look this project? "https://gitorious.org/qserialdevice":https://gitorious.org/qserialdevice[/quote]
I didn't know this, I'll try.
-
[quote author="Andre" date="1304426868"]Would spinning an eventloop while waiting for the signal be a solution for you? Or just use QxtSignalWaiter?[/quote]
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:
@
serialPort->write("123456\r\n");
serialPort->waitForReadyRead(10000);
int num_byte =serialPort->bytesAvailable();
if(num_byte>=10)
{
qDebug() << "Num BYTE: " << num_byte;
qDebug() << serialPort->read(num_byte);
}
@ -
[quote author="Andre" date="1304429607"]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. [/quote]
So sorry, I didn't understand you question.
As work-around I'll use this:
@
serialPort->write("123456\r\n");
while(1)
{
int num_byte =serialPort->bytesAvailable();
if(num_byte>=10)
{
qDebug() << "Num BYTE: " << num_byte;
qDebug() << serialPort->read(num_byte);
break;
}
}
@or something similar.
-
[quote author="stuk" date="1304425688"]Have you look this project? "https://gitorious.org/qserialdevice":https://gitorious.org/qserialdevice[/quote]
Thanks, It seems to works. I must do some tests but it goes in the right way.
-
[quote]As work-around I’ll use this:
@
serialPort->write("123456\r\n");
while(1)
{
int num_byte =serialPort->bytesAvailable();
if(num_byte>=10)
{
qDebug() << "Num BYTE: " << num_byte;
qDebug() << serialPort->read(num_byte);
break;
}
}
@or something similar.[/quote]
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:
@
QxtSignalWaiter waiter(serialPort, SIGNAL(readyRead());
serialPort->write("123456\r\n");
if (waiter.wait(10000)) {
int num_byte =serialPort->bytesAvailable();
if(num_byte>=10)
{
qDebug() << "Num BYTE: " << num_byte;
qDebug() << serialPort->read(num_byte);
}
} else {
//timeout waiting...
}
@Edit: if another serial port implementation works better, then that is obviously a much better solution than messing around with hacks like QxtSignalWaiter.
-
It is, but it does have its limitations. This is important to realize:
[quote]
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.[/quote]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.
-
This project is not very popular but for me is better than Qextserialport.
[quote author="Luca" date="1304430744"]
[quote author="stuk" date="1304425688"]Have you look this project? "https://gitorious.org/qserialdevice":https://gitorious.org/qserialdevice[/quote]Thanks, It seems to works. I must do some tests but it goes in the right way.[/quote]