ts-7000
[Top] [All Lists]

[ts-7000] Re: RS232 Questions/Problems

To:
Subject: [ts-7000] Re: RS232 Questions/Problems
From: "JD" <>
Date: Fri, 04 Jan 2008 18:27:51 -0000
An interesting thing I just saw on the linux box is that if (in a
simple case) have hyperterm connected and press keys, it works ok
until I disconnect and reconnect hyperterm (without restarting the
test app)

On the hyperterm restart, nothing I type into hyperterm registers as
being seen on the linux end.

Is it a frame error or some other signal occuring that is stopping
everything?
And if so, how do you detect and clear (or just plain old ignore)
errors coming in.
 
Windoze has a ClearCommError which gets and clears any errors - is
there a similar function I should use for linux?
 

--- In  "JD" <> wrote:
>
> running on my fedora 8 box, it runs just fine, using the exact same
> data source.
> 
> 
> --- In  Jim Jackson <jj@> wrote:
> >
> > 
> > 
> > 
> > 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/
 

<Prev in Thread] Current Thread [Next in Thread>
Admin

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