To: | |
---|---|
Subject: | Re: [ts-7000] Serial port configuration problem TS-7250 |
From: | "Don W. Carr" <> |
Date: | Fri, 16 Jun 2006 14:14:14 -0500 |
You might try my routine, it works at higher baud rates on the TS-7300. Use a timeout of zero if you want it to wait forever on a read (slave). int rt_open_serial(const char *port, int baud_rate, float timeout) { /* The following 3 could be parameters. */ int tmp_parity = 0; // no parity int tmp_data_bits = 8; // 8 data bits int tmp_stop_bits = 1; // 1 stop bit /***********/ int fd; struct termios rt_tio; /* open the serial port */ fd = open(port,O_RDWR | O_NOCTTY | O_NONBLOCK | O_NDELAY) ; if(fd < 0) { char buf[60]; snprintf(buf, sizeof(buf), "Opening %s", port); perror(buf) ; exit(-1) ; //return -1 ; } if (0 == isatty(fd)) { printf("This is NOT a tty device, will not set baud rate\n"); return fd; // It is not a tty, you won't be able to set the baud rate } else { printf("This is a tty device\n"); } /* save the old serial port settings */ if (tcgetattr (fd,&saved_tty_parameters) < 0) { perror("Can't get terminal parameters "); exit(-1) ; //return -1 ; } /* set the fields */ bzero(&rt_tio,sizeof(&rt_tio)); switch (baud_rate) { case 0: rt_tio.c_cflag = B0; break; case 50: rt_tio.c_cflag = B50; break; case 75: rt_tio.c_cflag = B75; break; case 110: rt_tio.c_cflag = B110; break; case 134: rt_tio.c_cflag = B134; break; case 150: rt_tio.c_cflag = B150; break; case 200: rt_tio.c_cflag = B200; break; case 300: rt_tio.c_cflag = B300; break; case 600: rt_tio.c_cflag = B600; break; case 1200: rt_tio.c_cflag = B1200; break; case 1800: rt_tio.c_cflag = B1800; break; case 2400: rt_tio.c_cflag = B2400; break; case 4800: rt_tio.c_cflag = B4800; break; case 9600: rt_tio.c_cflag = B9600; break; case 19200: rt_tio.c_cflag = B19200; break; case 38400: rt_tio.c_cflag = B38400; break; case 57600: rt_tio.c_cflag = B57600; break; case 115200: rt_tio.c_cflag = B115200; break; case 230400: rt_tio.c_cflag = B230400; break; default: rt_tio.c_cflag = B9600; } switch (tmp_data_bits) { case 7: rt_tio.c_cflag = rt_tio.c_cflag | CS7; break; case 8: default: rt_tio.c_cflag = rt_tio.c_cflag | CS8; break; } switch (tmp_parity) { case 1: rt_tio.c_cflag = rt_tio.c_cflag | PARENB; rt_tio.c_iflag = ICRNL; break; case -1: rt_tio.c_cflag = rt_tio.c_cflag | PARENB | PARODD; rt_tio.c_iflag = ICRNL; break; case 0: default: rt_tio.c_iflag = IGNPAR | ICRNL; break; } if (tmp_stop_bits == 2) rt_tio.c_cflag = rt_tio.c_cflag | CSTOPB; rt_tio.c_cflag = rt_tio.c_cflag | CLOCAL | CREAD; rt_tio.c_oflag = 0; rt_tio.c_lflag = 0; /*ICANON;*/ if (timeout == 0) { rt_tio.c_cc[VMIN]=1; rt_tio.c_cc[VTIME]=0; } else { rt_tio.c_cc[VMIN]=0; rt_tio.c_cc[VTIME]= (int)(timeout * 10.0); } /* flush the serial port */ tcflush(fd, TCIFLUSH); if (-1 == fcntl(fd, F_SETFL, FASYNC)) { perror("fcntl"); exit(-1) ; //return -1 ; } /* write the settings for the serial port */ if (tcsetattr(fd,TCSANOW,&rt_tio) <0) { perror("Can't set terminal parameters "); exit(-1) ; //return -1 ; } /* flush the serial port */ tcflush(fd,TCIOFLUSH); if (rt_verbose) { printf("serial port ok:\n"); printf("device name %s\n", port); printf("speed %d\n", baud_rate); printf("data bits %d\n", tmp_data_bits); printf("stop bits %d\n", tmp_stop_bits); printf("parity %d\n", tmp_parity); printf("timeout: %f\n", timeout); } return fd ; } On 6/16/06,
Tony Williams <> wrote:
|
<Prev in Thread] | Current Thread | [Next in Thread> |
---|---|---|
|
Previous by Date: | Re: [ts-7000] Graphics LCD Screen, Don W. Carr |
---|---|
Next by Date: | [ts-7000] rs485, Andrea Fino |
Previous by Thread: | [ts-7000] Serial port configuration problem TS-7250, Tony Williams |
Next by Thread: | [ts-7000] rs485, Andrea Fino |
Indexes: | [Date] [Thread] [Top] [All Lists] |
Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU