test_rs232::test_rs232(QObject *parent) : QObject(parent) { /** how to use it? **/ // open com3 emit com.sigOpenComm("com3"); // send data to com3 (it is very very easy to send data to com port. emit com.sigSendDatagram("Hello RS232 \n\r"); // handle the signal from com for data received. connect(&com,SIGNAL(sigDataReceived(QByteArray)), this,SLOT(onDataReceived(QByteArray))); }
void ListenThread::run( void ) { QObject::connect( this, SIGNAL(sigDataReceived(TN5500_Data)), &(MainWindow::Instance()), SLOT(sltDataReceived(TN5500_Data)), Qt::QueuedConnection ); QObject::connect( this, SIGNAL(sigListenTimedOut()), &(MainWindow::Instance()), SLOT(sltListenTimedOut()), Qt::QueuedConnection ); while ( 1 ) { if ( m_bActive ) { if ( m_Clock >= clock() ) { clib_probe_listen( this ); //clib_serial_flushrecv(); //Flush, only "packets" of data are considered valid } else { emit sigListenTimedOut(); m_bActive = false; } } QCoreApplication::processEvents( QEventLoop::AllEvents, 5 ); msleep( 1 ); } }
void ListenThread::dataReceived( const TN5500_Data& data ) { RefreshClock(); emit sigDataReceived( data ); }