views:

127

answers:

0

Hi all,

I have created a sample application from where separate thread is started to read and process data from serial port. QSocketNotifier is used for detecting whether data has arrived on the serial ports or not. I start an event loop using exec() statement in run function of thread. But while running the application only once the socket notifier has worked, the signal for serial port activation is never generated. And once when it was generated it was generated very fast and wasn't equivalent to the frame rate of sending device.

Here is a brief code sample for serial communicator thread:

SerialPortWatchOne.cpp

//constructor
klass::klass()
{
//setport configuration
//miscellaneous initialization
QSocketNotifier* notifier = new QSocketNotifier(mPort->GetFileDescriptor, QSocketNotifier::Read,this);
connect(notifier,SIGNAL(activated(int)),this,SLOT(ReadAndProcessData()));
}

void klass::run()
{
exec();  //this starts an event loop where by Qt signal handling is enabled
}

void klass::ReadAndProcessData()
{
      FlushBuf();      
      int bytes_read=mPort->ReadPort(mBuf,1000);
      if(bytes_read>0)
         //Process data
}

Note: klass is a thread and a member of GUI thread and is instantiated in the GUI thread c'tor. periodically GUI updates its widgets with data from klass thread.

Can anyone suggest as what the issue is? Has someone done this before.