2017-12-20 6 views
-1

Hellolunux에서 C++을 사용하는 두 개의 직렬 포트에 intrrupt 처리기가 필요합니다.

내 프로그램에 두 개의 직렬 포트가 있습니다. 직렬 포트 초기화 및 기능을위한 클래스가 있습니다. 직렬 포트를 열어서 기능을 열면. 하지만 다른 직렬 포트 정보를 보내고이 함수에서 인터럽트 처리기를 설정하면 첫 번째 직렬 포트는 인터럽트 처리기로 수신되지 않습니다.

serial_port_init::serial_port_init(char *sp_name,speed_t baud,void (*event_func)(int32_t)){ 
struct termios termAttr; 
struct sigaction saio; 
sp = open(sp_name, O_RDWR | O_NOCTTY | O_NDELAY); 
saio.sa_handler = (event_func); 
saio.sa_flags = 0; 
saio.sa_restorer = NULL; 
sigaction(SIGIO,&saio,0); 

fcntl(sp, F_SETFL, FNDELAY); 
fcntl(sp, F_SETOWN, getpid()); 
fcntl(sp, F_SETFL, O_ASYNC); 

tcgetattr(sp,&termAttr); 
cfsetispeed(&termAttr,baud); 
cfsetospeed(&termAttr,baud); 
termAttr.c_cflag &= ~PARENB; 
termAttr.c_cflag &= ~CSTOPB; 
termAttr.c_cflag &= ~CSIZE; 
termAttr.c_cflag |= CS8; 
termAttr.c_cflag |= (CLOCAL | CREAD); 
termAttr.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); 
termAttr.c_iflag &= ~(IXON | IXOFF | IXANY); 
termAttr.c_oflag &= ~OPOST; 
tcsetattr(sp,TCSANOW,&termAttr); 
tcgetattr(sp, &termAttr); 

나는 시리얼 포트

serial_port_init link_sp(link_usart_addr,link_usart_baud,&link_get_all_data_event); 

으로 초기화 호출하고 지금은 그들 모두에게 intrupt이 필요합니다. 감사 같은

+0

* "나는 ... 두 개의 시리얼 포트에 대한 intrrupt [원문] 핸들러가 필요합니다"* - 아니, 당신은하지 않습니다. 커널은 이미 이러한 장치에 대한 인터럽트 처리기를 가지고 있습니다. 응용 프로그램에는 장치에 대한 인터럽트 처리기가 없습니다. 분명히 [XY 질문] (https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)을 요청하고 있습니다. – sawdust

+0

어떻게 일부 기능을 실행하는 데 사용할 수 있습니다. –

답변

0

뭔가 :

static void handler(int sig) 
{ 
    printf ("Hello world from handler\n"); 
} 

serial_port_init link_sp(link_usart_addr,link_usart_baud,&handler); 
+0

내가 정적 인 Qt 처리기를 정의 할 때 정의되지 않았다. –

+0

나는 그것을한다. 그러나 문제를 해결하지 않는다. –

+0

Pls 컴파일러 메시지를 게시한다. – mbieren

관련 문제