Re: [Ftdi-usb-sio-devel] 62 bytes... comes from where?
Brought to you by:
bryder
From: Kentaro F. <fu...@is...> - 2002-10-03 07:21:43
|
Hello, Some addition to my previous mail. Our code works well with FTDI's driver for Windows. I have read the driver code and realized the meaning of 62 bytes. I modified driver to dump some debug messages. We had got a lot of TTY_OVERRUN when the baud rate was 700Kbps. I can't belive that our machine is not fast enough to receive 700Kbps data (Pentium4 1.7GHz). Here is a test code to receive data from usbserial. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <termios.h> #include <errno.h> #include <linux/serial.h> #include <asm/ioctls.h> #include <sys/time.h> #define DATA_LENGTH 769 int fd; int device_open(char *filename) { struct termios tty; fd = open(filename, O_RDWR); if(fd < 0) return -1; tcgetattr(fd, &tty); tty.c_cflag = CS8|CREAD|CLOCAL|B38400; tty.c_iflag = IGNBRK; tty.c_oflag = 0; tty.c_lflag = 0; tty.c_line = 0; tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 1; tcsetattr(fd, TCSAFLUSH, &tty); return 0; } int main(int argc, char **argv) { struct serial_struct serinfo; unsigned char buf[800]; int ret; int x, y, ymax; int p; struct timeval t1, t2; int total_byte = 0; int ttt; int i, j; if(argc != 2) { puts("missing device file name"); exit(1); } if(device_open(argv[1])) { perror("failed to open device: "); exit(1); } serinfo.reserved_char[0] = 0; if(ioctl(fd, TIOCGSERIAL, &serinfo) < 0) { perror("failed to get serial info"); exit(1); } printf("Baud_base: %d, divisor: %d\n", serinfo.baud_base, serinfo.custom_divisor); serinfo.custom_divisor=34; serinfo.flags |= ASYNC_SPD_CUST; if(ioctl(fd, TIOCSSERIAL, &serinfo) < 0) { perror("failed to set serial info"); exit(1); } while(1) { gettimeofday(&t1, NULL); for(i=0; i<100; i++) { buf[0] = 0xff; ret = write(fd, buf, 1); if(ret != 1) { puts("w?"); } total_byte = 0; while(total_byte < DATA_LENGTH) { ret = read(fd, buf, DATA_LENGTH-total_byte); printf("ret %d\n", ret); if(ret < 0) { if(errno != EAGAIN) { perror(""); } } else { total_byte += ret; } } } gettimeofday(&t2, NULL); ttt = (t2.tv_sec - t1.tv_sec)*1000000 + t2.tv_usec - t1.tv_usec; printf("bps = %f\n", (float)DATA_LENGTH * 800 * 1000000/ ttt); } return 0; } Any suggestion are welcome. Kentaro Fukuchi |