我正在开发一个通过串行端口 uart ttyS0 发送信息的嵌入式系统。现在我想从同一个串口接收数据。所以我使用 sigaction 实现了一个信号处理程序。我想使用 SIGIO 信号,但问题是由于我发送的数据而出现中断。那么我可以在阻止输出信号的方法中设置一个条件吗?
struct sigaction act;
memset(&act,0, sizeof(act));
act.sa_handler = &sigio_Handler;
//act.sa_flags=0;
//act.sa_restorer=NULL;
fcntl(this->stream_ ,F_SETFL, FNDELAY|FASYNC);
fcntl(this->stream_,F_SETOWN,getpid());
sigaction(SIGIO,&act,0);
void DataSender::sigio_Handler(int signo){
int fd;
std::cout << "helloworld1" << "\n";
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
std::cout << "helloworld2" << "\n";
if(signo == SIGIO ){
unsigned char rx_buffer[3];
int rx_length = read(fd, (void*) rx_buffer,3);
std::string mode;
mode+=rx_buffer[0];
mode+=rx_buffer[1];
std::cout << "helloworld3" << std::endl;
std::cout << rx_buffer << std::endl;
std::cout << mode << std::endl;
std::cout << (int)rx_buffer[2] << std::endl;
projectionMode = mode;
if (rx_length == -1 ){
std::cout << "could not read"<< std::endl;
}
if (rx_buffer[2] == 1){
std::cout << "could not read1"<< std::endl;
}else if(rx_buffer[2] == 2){
}else if(rx_buffer[2] == 3){
}else if(rx_buffer[2] == 4){
}
}
}