gpt4 book ai didi

linux - 我需要在linux中用c++为两个串口提供一个中断处理程序

转载 作者:太空宇宙 更新时间:2023-11-04 05:16:54 24 4
gpt4 key购买 nike

你好

我的程序中有两个串口。我有串口初始化和功能类。当我发送串口以打开它时。但是当我发送另一个串口信息并在此函数中设置中断处理程序时,第一个串口无法使用中断处理程序接收。

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);

现在我需要他们两个的中断。谢谢

最佳答案

类似这样的事情:

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

serial_port_init link_sp(link_usart_addr,link_usart_baud,&handler);

关于linux - 我需要在linux中用c++为两个串口提供一个中断处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47903552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com