|
ru.unix.bsd- RU.UNIX.BSD ------------------------------------------------------------------ From : Sergey Terekhin 2:5020/400 11 Mar 2003 15:09:42 To : All Subject : -pthread and reading from port -------------------------------------------------------------------------------- Hаписана тестовая программа для работы с определенным устройством через com порт. Проблема в следующем: с -pthread не читает из порта, без -pthread - читает. Подскажите плз. в чём тут может быть дело? uname -a FreeBSD tri 4.7-STABLE FreeBSD 4.7-STABLE #1: Fri Jan 24 17:45:19 EET 2003 yoris@tri:/usr/obj/usr/src/sys/TRI i386 -------------------------- test.c ---------------------- #include <fcntl.h> #include <sys/types.h> #include <sys/uio.h> #include <unistd.h> #include <stdio.h> #include <termios.h> #include <string.h> #include <ctype.h> int mode(int, long, char, int, int, long); int main(int argc, char** argv) { int res = 0; int fd = open("/dev/cuaa0", O_RDWR | O_NOCTTY); if (fd < 0) { printf("Cannot open port");fflush(stdout); return 1; } mode(fd, 9600, 'E', 8, 1, 100); u_int mctl; if (ioctl(fd, TIOCMGET, &mctl) < 0) return 2; mctl &= ~TIOCM_DTR; mctl &= ~TIOCM_RTS; if (ioctl(fd, TIOCMSET, &mctl) < 0) return 3; u_char buf[258] = { 0x00 }; size_t len = 258; tcflush(fd, TCIOFLUSH); tcdrain(fd); res = write(fd, buf, 1); /* fd_set rfds; FD_ZERO(&rfds); FD_SET(fd, &rfds); select(fd + 1, &rfds, 0, 0, 0); if (FD_ISSET(fd, &rfds))*/ res = read(fd, buf, len); if (res == 0) { printf("\nShit!!!\n"); } else { printf("\nReaded %d bytes\n", res); for (int i = 0; i < res; i++) printf("%d ", buf[i]); printf("\n"); } close(fd); return 0; } int mode(int fh, long baud, char parity, int bits, int stopbits, long timeout) { int options; struct termios tio; options = TCSANOW; if (tcgetattr(fh, &tio) < 0) return -1; if (baud != -1) { options = TCSAFLUSH; if (cfsetospeed(&tio, baud) < 0) return -1; if (cfsetispeed(&tio, 0) < 0) return -1; } if (parity > 0) { options = TCSAFLUSH; parity = toupper(parity); tio.c_cflag &= ~(PARENB|PARODD|INPCK); if (parity != 'N') { tio.c_cflag |= PARENB|INPCK; if (parity == 'O') tio.c_cflag |= PARODD; else if (parity != 'E') return -1; } } if (bits != -1) { options = TCSAFLUSH; tio.c_cflag &= ~CSIZE; switch(bits) { case 7: tio.c_cflag |= CS7; break; case 8: tio.c_cflag |= CS8; break; default: return -1; } } if (stopbits != -1) { options = TCSAFLUSH; tio.c_cflag &= ~CSTOPB; if (stopbits != 1) tio.c_cflag |= CSTOPB; } if (timeout != -1) { memset(tio.c_cc, 0, sizeof(tio.c_cc)); if (timeout < 25500) tio.c_cc[VTIME] = timeout / 100; else tio.c_cc[VTIME] = 255; } tio.c_cflag |= CREAD|HUPCL|CLOCAL; tio.c_cflag &= ~CRTSCTS; tio.c_iflag = 0; tio.c_oflag = 0; tio.c_lflag = 0; tio.c_cc[VMIN] = 0; if (tcsetattr(fh, options, &tio) < 0) { return -1; } return 0; } -- Сергей Терёхин AKA March Rabbit 11 March, Tuesday 13:02 Gnus v5.9.0(GNU/Emacs 21.2.1)*FreeBSD 4.7 --- ifmail v.2.15dev5 * Origin: ... Follow the March Rabbit ... (2:5020/400) Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.unix.bsd/23321315a96a3.html, оценка из 5, голосов 10
|