On Wednesday, July 20, 2016 at 1:56:50 AM UTC-5, Regina Choi wrote:
>
>
> Hi, 
>
> I have programmed (in C) UART4 read in thread with blocking read, the code 
> as below: I confirmed that the UART receive port does have data through 
> oscilloscope, but somehow there is no data in read( ), the return count 
> always zero ?  
>
>
> // UART RX thread
> void* uartRxWait(void *param){
>
>     unsigned char receive[100];
>     int count, n;
>     fd_set input;
>     struct timeval timeout;
>
>     //initialize input set
>     FD_ZERO(&input);
>     FD_SET(file, &input);
>
>     timeout.tv_sec=0;
>     timeout.tv_usec=0;
>
>     while(1){
>        
>             if ((count = read(file, (void *)receive, 100))<0)
>             {
>                 perror("Failed to read from input \n");
>                 printf("count = %d\n", count);
>             }else{
>
>                 if(receive[2]==0x32){
>                     printf("Header received \n"); 
>                 }
>                     printf("Byte received [%d] \n", count);
>                     printf("Value of Pi = 0x%.2x\n", receive[0]);
>
>           }
>  
>     }
>
>     pthread_exit(0);
> }
>

Try adding fflush(stdout) and fflush(stderr) as the last statements in your 
while loop so you can see the outputs while the thread is running.

You thread code looks funky,  main() launches the threads and then 
immediately drops into phtread_join to wait for the Rx thread to terminate, 
which doesn't look like it'll happen without killing the program.  Or have 
you left out some of your code?

Another potential problem is that it looks like you send the command in 
main before launching the thread to receive the reply.

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/9c9cdc43-7f45-4cec-bab9-722f084cddb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to