
現在linuxマルチスレッドのプログラムでシリアル通信の受信をやっております.
プログラム起動後数回は受信に成功するのですが, その後全く受信することができません.原因がわかる方がいらっしゃいましたらご教授お願い致します.
C
1シリアルを開く関数 2int open_serial_port( char* modem_dev ){ 3 struct termios newtio; 4 5 fd[0] = open( modem_dev, O_RDWR | O_NOCTTY | O_NONBLOCK ); 6 if( fd[0] < 0 ){ 7 fprintf( stderr, "open error\n" ); 8 return -1; 9 } 10 11 fcntl( fd[p], F_SETOWN, getpid() ); 12 fcntl( fd[p], F_SETFL, FASYNC ); 13 tcgetattr( fd[p], &oldtio ); //save 14 15 newtio.c_iflag = 0; 16 newtio.c_oflag = 0; 17 newtio.c_cflag = 0; 18 newtio.c_lflag = 0; 19 newtio.c_line = 0; 20 bzero( newtio.c_cc, sizeof( newtio.c_cc ) ); 21 22 cfsetispeed( &newtio, BAUDRATE ); 23 cfsetospeed( &newtio, BAUDRATE ); 24 25 newtio.c_cflag |= ( CLOCAL | CREAD ); 26 27 newtio.c_cflag &= ~PARENB; 28 newtio.c_cflag &= ~CSTOPB; 29 newtio.c_cflag &= ~CSIZE; 30 newtio.c_cflag |= CS8; 31 newtio.c_cflag &= ~CRTSCTS; 32 33 newtio.c_lflag &= ~( ICANON | ECHO | ECHOE | ISIG ); 34 newtio.c_iflag = ( IGNPAR | IGNCR ); 35 newtio.c_iflag &= ( IXON | IXOFF | IXANY ); 36 37 newtio.c_oflag &= ~OPOST; 38 39 newtio.c_cc[VTIME] = 0; 40 newtio.c_cc[VMIN] = 1; 41 42 /* clear the modem line */ 43 tcflush( fd[p], TCIFLUSH ); 44 tcsetattr( fd[p], TCSANOW, &newtio ); 45 46 return 0; 47}
C
1シリアル受信のスレッドです 2 3void* thread0(){ 4 struct sigaction action; 5 struct sigevent evp; 6 7 k1 = 0; 8 k2 = 0; 9 10 pthread_mutex_init( &mutex0, NULL ); 11 pthread_cond_init( &cond0, NULL ); 12 13 memset( &action, 0, sizeof(action) ); 14 memset( &evp, 0, sizeof(evp) ); 15 16 action.sa_sigaction = SignalHandler; 17 action.sa_flags = SA_SIGINFO | SA_RESTART; 18 sigemptyset( &action.sa_mask ); 19 20 evp.sigev_notify = SIGEV_SIGNAL; 21 evp.sigev_signo = SIGIO; 22 23 if( sigaction( SIGIO, &action, NULL ) < 0 ){ 24 perror( "sigaction error" ); 25 return -1; 26 } 27 28 while(1){ 29 pthread_mutex_lock( &mutex0 ); 30 pthread_cond_wait( &cond0, &mutex0 ); 31 32 memset( buffer, '\0', sizeof(buffer) ); 33 34 k = read( fd[0], buffer, sizeof(buffer) ); 35 printf( "receive char : %d \n" , k ); 36 37 38 if( k > 0 ){ 39 40 // save buffer to rs_rbuffer and alz_buffer k byte ( k:受信したバイト数 ) 41 memcpy( &rs_rbuffer[k1], buffer, k ); 42 memcpy( &alz_buffer[k1], buffer, k ); 43 44 k1 += k; 45 k2 += k; 46 47 pthread_cond_signal( &cond1 ); 48 49 } 50 pthread_mutex_unlock( &mutex0 ); 51 52 } 53 54 pthread_exit(0); 55} 56
C
1シグナル 2 3// SIGIO handler 4void* SignalHandler(int signum, siginfo_t *info, void* ctxt){ 5 pthread_cond_signal( &cond0 ); 6} 7

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/10/25 07:37 編集
退会済みユーザー
2016/10/25 12:06