Читалка
int fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
termios PortSettings;
tcgetattr(fd,&PortSettings);
PortSettings.c_cflag |= (CLOCAL | CREAD); // Активируем приемник, разрешая чтение
PortSettings.c_lflag |= ~(ICANON | ECHO | ECHOE | ISIG);
PortSettings.c_oflag |= ~OPOST;
PortSettings.c_iflag |= ~(IXON | IXOFF | IXANY);
cfsetispeed(&PortSettings, B19200);
cfsetospeed(&PortSettings, B19200);
tcsetattr(fd,TCSANOW,&PortSettings);
ssize_t TeakedByteCounter;
size_t SendingByteCounter = 1;
void *buff = NULL;
fcntl(fd, F_SETFL, 0); // blocking on
TeakedByteCounter = ::read(fd,buff,SendingByteCounter);
::close(fd);
int fd = open("/dev/ttyS2", O_RDWR | O_NOCTTY | O_NDELAY);
termios PortSettings;
tcgetattr(fd,&PortSettings);
PortSettings.c_cflag |= (CLOCAL | CREAD);
PortSettings.c_lflag |= ~(ICANON | ECHO | ECHOE | ISIG);
PortSettings.c_oflag |= ~OPOST;
PortSettings.c_iflag |= ~(IXON | IXOFF | IXANY);
cfsetispeed(&PortSettings, B19200);
cfsetospeed(&PortSettings, B19200);
tcsetattr(fd,TCSANOW,&PortSettings);
ssize_t SendedByteCounter;
SendedByteCounter = write(fd,"a",1);
::close(fd);
Собстевнно:
read(fd,buff,SendingByteCounter) == -1