There is a code
int open_port() { int fd; /* Файловый дескриптор для порта */ fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { /* Не удалось открыть порт */ /* perror() выводит сообщение (в стандартный поток ошибок), затем описание последней случившейся ошибки (на основании errno) */ perror("open_port: Unable to open /dev/ttyS0 - "); } else { /* Порт успешно открыт */ /* fcntl выполняет одну из различных дополнительных операций над файловым дескриптором fd */ /* F_SETFL - Устанавливает часть флагов, относящихся к состоянию файла, согласно значению, указанному в аргументе arg. (0) */ fcntl(fd, F_SETFL, 0); printf("Ok - Port open!\n"); } return (fd); } int main(int argc, char **argv) { system("clear"); int fd; fd = open_port(); /* ----------------- Запись ------------------*/ int n; /* Количество посланных байт(write) */ char buf[] = "qwertyuiop"; /* Буффер ввода */ int length; /* Длина строки ввода (Количество байт) */ length = strlen(buf); n = write(fd, buf, length); /* write возвр. -1 при ошибке */ /* stderr - стандартный поток ошибок */ if (n == -1) { fputs("Записать не удалось!\n", stderr); } else { printf("Успешно записано %d байт(а) \n", n); } /* ------------------ Чтение ---------------- */ int k,i; fcntl(fd, F_SETFL, FNDELAY); char buf1[10]; k = read(fd, buf1, length); if (k == -1) { printf("buffer = %s, Kod = %d \n", buf1, k); printf("Ошибка чтения!\n"); } else { printf("buffer = %s, Kod = %d \n", buf1, k); } close(fd); printf("Ok - Port Close!\n\n"); return 0; } Which should read and write to the comport. He writes regularly, but he does not read from it. The code is not entirely mine, and I understand the subject a little, therefore I have 2 questions, the first how to read from the port com and the 2nd where to read how it works. The com port is now self-contained on my TXD on the RXD via the mini-it works.
strerror(errno)in case of errors. - Fat-Zerminicomthread or at leastcathave already checked that the port / jumper / is something still functioning correctly? - Fat-Zer