serial port에 대한 read error
글쓴이: yklee8 / 작성시간: 수, 2003/10/29 - 10:24오후
안녕하세요.
linux에서 RJ-45 포트(serial COM2) 로 통신을 할려고 하는데, write는 되는데 read가 안되네요. 그리고 baud rate 변경도 안되고요.
코드는 다음과 같습니다.
#define ChangeBaudRate(fd, baud) ioctl((fd), 1, (baud)) int fDis() { int fd, n; int i; int ii; int rval; int read_no, no; int sleep_cnt = 0; char buf[5]; char tmpbuf[255]; struct timeval timeout; unsigned char checkbit = 0x80; fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd < 0) { close(fd); return (rval); } n = ChangeBaudRate(fd, 9600); for (no = 0; no < 8; no++) { /* Buf Clear */ n = NonBlockRead(fd, tmpbuf, 255); /* Write Sx100 */ strcpy(buf, "S0100"); buf[1] = 0x30+no; n = write(fd, buf, 5); if (n != 5) { rval = 3; close(fd); return (rval); } /* Sleep for sync */ timeout.tv_sec = 0; timeout.tv_usec = 100000; rval = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout); /* read */ n = read(fd, buf, 5); printf("buf = %s, n = %d\n", buf, n); for (i = 0; i < 8; i++) { strcpy(buf, "S0700"); buf[1] = 0x30+i; n = write(fd, buf, 5); if (n != 5) { close(fd); return (rval); } timeout.tv_sec = 0; timeout.tv_usec = 50000; rval = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout ); } } close(fd); return (rval); }
Forums:
댓글 달기