On Fri, 4 Jan 2008, JD wrote:
> I have a simple example, using non blocking read that works _most_ of
> the time.
>
> It will start reading ok and print out the number of characters read
> when a stream of data is applied, but after maybe 10 seconds, it stops
> reading anything (read returns 0) even though data is being sent.
>
> Any ideas on why it would stop?
Unfortunately No. Have you checked the same program and device on a
desktop linux box? Does it all work ok?
>
> Code:
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <string.h>
> #include <unistd.h>
> #include <termios.h>
> #include <sys/ioctl.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <inttypes.h>
>
>
> void termConfigRaw(int fd,struct termios *saved,int baud_Enum);
>
> /*------------------------------------------------------------*/
> int UART_init(uint8_t port, uint32_t baudrate)
> {
> int hCom = -1;
> struct termios oldtio;
> char buffer[100];
>
> sprintf(buffer,"/dev/ttyS%d", (port));
>
> printf("try open %d : '%s'\r\n", (int)port, buffer);
>
> hCom = open(buffer, O_RDWR | O_NOCTTY | O_NDELAY);
> if (hCom == -1)
> {
> fprintf(stderr,"OpenSerial: Couldnt open %s:", buffer);
> fflush(stderr);
> perror(NULL);
> return -1;
> }
> termConfigRaw(hCom,&oldtio,baudrate);
>
> // fcntl(hCom, F_SETFL, FNDELAY);
>
> return hCom;
> }
>
> /*------------------------------------------------------------*/
> void termConfigRaw(int fd,struct termios *saved,int baud_Enum) {
> struct termios newtio;
> int err;
>
> err = tcgetattr(fd,saved); /* save current port settings */
> printf("tcgetattr: %d\r\n", err);
> perror("tcgetattr:");
>
> /* Start with old settings, then we'll modify */
> newtio = *saved;
>
> /* Set baudrate */
> cfsetispeed(&newtio,baud_Enum);
> cfsetospeed(&newtio,baud_Enum);
>
> newtio.c_cflag |= CREAD;
> newtio.c_cflag &= ~CLOCAL;
>
> // 8N1
> newtio.c_cflag &= ~PARENB;
> newtio.c_cflag &= ~CSTOPB;
> newtio.c_cflag &= ~CSIZE;
> newtio.c_cflag |= CS8; /* Set for 8 bits. */
>
> /* disable hardware flow control. */
> newtio.c_cflag &= ~CRTSCTS;
>
> /* When we read, we want completely raw access */
> /* the last two get set by default on ARM but not CYGWIN */
> newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG | NOFLSH | TOSTOP);
> newtio.c_lflag = 0; // We don't believe above signals are set
> correctly...
>
> /* ignore flow control, don't do CR/LF translations */
> newtio.c_iflag &= ~(IXON | IXOFF | IXANY | ICRNL | INLCR | IGNCR);
>
> /* Set output filtering to raw. */
> newtio.c_oflag &= ~(OPOST | ONLCR | OCRNL | ONLRET);
>
> /* Set readsize and timeout to some reasonable values, just to be
> safe*/
> newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
> newtio.c_cc[VMIN] = 0; /* nonblocking read */
>
> tcflush(fd, TCIFLUSH);
> err = tcsetattr(fd,TCSANOW,&newtio);
> printf("tcsetattr: %d\r\n", err);
> perror("tcsetattr:");
> }
>
> int main()
> {
> int f = UART_init(0,B57600);
> int ch;
> int len;
> char buff[256];
>
> if(f == -1)
> perror("No UART!:");
> else
> {
> while(1)
> {
> len = read(f, buff,sizeof(buff));
>
> if(len != 0) printf("%d\r\n", len);
> }
> }
>
> return 0;
> }
>
>
>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|