To: | |
---|---|
Subject: | [ts-7000] Re: RS232 Questions/Problems |
From: | "JD" <> |
Date: | Fri, 04 Jan 2008 15:22:07 -0000 |
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? 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; } __._,_.___
Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required) Change settings via email: =Email Delivery: Digest | m("yahoogroups.com?subject","ts-7000-fullfeatured");=Change Delivery Format: Fully Featured">Switch to Fully Featured Visit Your Group | Yahoo! Groups Terms of Use | =Unsubscribe __,_._,___ |
<Prev in Thread] | Current Thread | [Next in Thread> |
---|---|---|
|
Previous by Date: | [ts-7000] Re: cannot exec cc1 message, edaudio2000 |
---|---|
Next by Date: | Re: [ts-7000] Re: RS232 Questions/Problems, Jim Jackson |
Previous by Thread: | RE: [ts-7000] Re: RS232 Questions/Problems, Robert Bond |
Next by Thread: | Re: [ts-7000] Re: RS232 Questions/Problems, Jim Jackson |
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