Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

QtSerialPort - Problem with waitForReadyRead() and bytesAvailable()

$
0
0
Hello I can’t get the functions waitForReadyRead() and bytesAvailable() to work as I expect them to. I’m using Qt 4.7.4, Win 7, MinGW compiler. QtSerialPort downloaded 11 Feb 2013. The code in short is:     openSerialPort();     if(serial->isOpen())     {         serial->flush();           RS232Cmd[0] = 0x1B; // 2 bytes, Esc A         RS232Cmd[1] = 'A';           serial->write(RS232Cmd,2);         serial->waitForBytesWritten(100);           bTest = serial->waitForReadyRead(5000);         qDebug("w %d", bTest);           temp_value  = serial->bytesAvailable();         temp_value2 = serial->read(RS232Buffer, 8);         qDebug("a %d", temp_value);         qDebug("r %d", temp_value2);           closeSerialPort();     } The output I get is this: w 0 a 0 r 0 First of all, with the 5000 parameter to waitForReadyRead(); I expect the program to wait 5 seconds before displaying the debug output if no data comes in, but there is no wait time that I can notice. Second, I can see on the oscilloscope that the two bytes (‘Esc’ + ‘A’) are sent and that a 8 byte reply is received within 2ms. Third, with a terminal program I can verify that the 8 byte reply is correctly received on the PC. Any ideas on what’s going wrong? Or have I misunderstood the functionality of these functions?

Viewing all articles
Browse latest Browse all 18427

Trending Articles