Я вот такое подсмотрел(+). Вроде все работает нормально. Как только посмотреть сколько в буфере лежит?
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено Kukaracha 20 сентября 2004 г. 12:30
В ответ на: Открываеш /dev/ttyS0 как обычный файл, через ioctl задаеш параметры (скорость итд) и все. отправлено artem 20 сентября 2004 г. 12:10

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