Home > Mobile >  Qt4 fd of serial port using QSocketNotifier binding equipment, why can't receive the data?
Qt4 fd of serial port using QSocketNotifier binding equipment, why can't receive the data?

Time:11-10

Ubuntu, environment problems such as the title, help you a great god:
1. In Qt4, write a SerialPort class inheritance in QFile, do a series of operations: open the serial port equipment, set the baud rate, parity, etc.; the data bits
2. And then create a QSocketNotifier object binding the fd, mainly its readable state monitoring, the purpose is returned when there is data from serial port, and normal processing, as follows:
 
Rn=new QSocketNotifier (QFile: : handle (), QSocketNotifier: : Read);
Connect (rn), SIGNAL (the activated (int)), and this, SLOT (dataArrived ()));

3. Because of this test is NB module, through a serial port in the test code written to the AT command, such as sending data to the server, upload all is normal, but there is a strange place, the groove function did not trigger written above, namely the data read from the serial port is less than, cause a lot of can't get the AT command to the result of the need, groove function is as follows:
 
Void SerialPort: : dataArrived ()
{
Char buf [1024].
Int len=QFile: : readData (buf, sizeof (buf));
Len=m_inBuf. Write (buf, len);
{
QMutexLocker locker (& amp; M_lock);
AvailData=(https://bbs.csdn.net/topics/m_inBuf.size);
}
If (availData & gt;=_rthreshold) emit readyRead ();
}


Supplement:
1. Separate debugging module is normal, the module was not damaged;
2. The baud rate of serial port Settings such as normal; Writing is no problem;
3. If you just write a instruction, is can't read data; But if you build a 1 second, write 10 consecutive instructions, in the final can obtain the data to a read function, but it is not always successful,

Check some information found that others have encountered similar problems, please pass by the great spirit of your advice, thanks!
  •  Tags:  
  • Qt
  • Related