|
int ComPortOpen(char Port[], long BaudRate)
{
int fd;
struct termios options;
struct sigaction saio; //definition of signal action
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
if(fd < 0) return fd;
//install the serial handler before making the device asynchronous
saio.sa_handler = SignalHandlerIO;
sigemptyset(&saio.sa_mask); //saio.sa_mask = 0;
saio.sa_flags = 0;
saio.sa_restorer = NULL;
sigaction(SIGIO,&saio,NULL);
// allow the process to receive SIGIO
fcntl(fd, F_SETOWN, getpid());
// Make the file descriptor asynchronous (the manual page says only
// O_APPEND and O_NONBLOCK, will work with F_SETFL...)
fcntl(fd, F_SETFL, FASYNC);
tcgetattr(fd,&oldtio); // save current port settings
// set new port settings for canonical input processing
options.c_cflag = B57600 | CRTSCTS | CS8 | CLOCAL | CREAD;
options.c_iflag = IGNPAR;
options.c_oflag = 0;
options.c_lflag = 0; //ICANON;
options
.c_cc[VMIN]=1;
options.c_cc[VTIME]=0;
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&options);
return fd;
}
E-mail: info@telesys.ru