Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect() not Working in thread
    text
    copied!<p>I have to monitor a serial port and process its data. As a test program I was using select for just one port. The run function is as follows:</p> <pre><code>void &lt;ProtocolClass&gt;::run() { int fd = mPort-&gt;GetFileDescriptor(); fd_set readfs; int maxfd=1; int res; FD_ZERO(&amp;readfs); FD_SET(fd,&amp;readfs); struct timeval Timeout; Timeout.tv_usec=0; Timeout.tv_sec=3; //BYTE ack_message_frame[ACKNOWLEDGE_FRAME_SIZE]; while(true) { usleep(10); res=select(maxfd,&amp;readfs,NULL,NULL,NULL); if(res&lt;0) perror("\nselect failed"); else if( res==0) puts("TIMEOUT"); else if(FD_ISSET(fd,&amp;readfs)) {//IF INPUT RECEIVED qDebug("************RECEIVED DATA****************"); FlushBuf(); qDebug("\nReading data into a read buffer"); int bytes_read=mPort-&gt;ReadPort(mBuf,1000); mFrameReceived=false; for(int i=0;i&lt;bytes_read;i++) { qDebug("%x",mBuf[i]); } //if complete frame has been received, write the acknowledge message frame to the port. if(bytes_read&gt;0) { qDebug("\nAbout to Process Received bytes"); ProcessReceivedBytes(mBuf,bytes_read); qDebug("\n Processed Received bytes"); if(mFrameReceived) { int no_bytes=mPort-&gt;WritePort(mAcknowledgeMessage,ACKNOWLEDGE_FRAME_SIZE); }//if frame received }//if bytes read &gt; 0 } //if input received }//end while } </code></pre> <p>But the problem is it doesn't seemed to work as nothing happens. Can somebody suggest the correct way to do it. I want to use select per thread. Is this feasible. Can you give me a sample code to do it. I have searched the net but the examples are very basic involving just the main function. There are no C++ specific examples. I am using Qt threads by the way.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload