This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Non-blocking mode read from serial port


Ok thanks again

 I have changed the VTIME to "0" and VMIN to "1" to read only one character from the /dev/ser1 but i can only read 128 or 0, something wrong?The option O_NONBLOCKING is on eCos not supported?

The code:
/***************************************************************************
include<termios.h>        /*POSIX terminal control definitions*/
#include<stdio.h>          /*standard input/output definitions*/
#include<stdlib.h>         
#include<unistd.h>         /*UNIX standard functions definitions*/
#include<fcntl.h>          /*File control definitions*/
#include<errno.h>          /*error numbre definitions*/
#include<string.h>         /*string functions definitions*/
#include<sys/signal.h>     /*available signals definitions*/
#include<sys/types.h>


#define BAUDRATE B4800
#define MODEMDEVICE "/dev/ser1"
#define ENDMINITERM 2 /* ctrl-b to quit miniterm */

#define _POSIX_SOURCE 1 /* POSIX compliant source */

#define FALSE 0
#define TRUE 1

volatile int STOP=FALSE; 

int main(void)
{
int fd,nummer;
 int c;
struct termios oldtio,newtio;

fd = open(MODEMDEVICE, O_RDWR);
if (fd <0) {perror(MODEMDEVICE); exit(-1); }

tcgetattr(fd,&oldtio); /* save current modem settings */

newtio.c_cflag = BAUDRATE | CLOCAL | CREAD;
newtio.c_cflag &= ~PARENB;
newtio.c_cflag &= ~CSTOPB;
newtio.c_cflag &= ~CSIZE;
newtio.c_cflag |= CS8;

newtio.c_iflag = IGNPAR;

newtio.c_lflag = 0;
newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

newtio.c_cc[VMIN]=1;
newtio.c_cc[VTIME]=0;
cfsetispeed(&newtio, B4800);

tcsetattr(fd,TCSANOW,&newtio);

 while(1)
{
    nummer= read(fd,&c,1);
     printf("data = %d\n", c);
     if(c == 'z')
       { 
	 tcsetattr(fd, TCSANOW, &oldtio);
	 return 0;
       }
}

}
/*************************************************************************/
Jonathan Larmour <jifl@eCosCentric.com> schrieb am 23.02.04 14:46:18:
> 
> Ali Rodgo wrote:
> > Hello,
> > I would like to read from the serial port in non-blocking mode, EB40A.
> > 
> > I am trying to read from the /dev/ser1 port with the following configuration:
> > newtio.c_cc[VMIN]=0 
> > 
> > newtio.c_cc[VTIME]=1
> > 
> 
> I'm afraid VTIME != 0 isn't supported, sorry. Either the sources will need 
> to be enhanced (I know what to do, but don't have time to do it), or you 
> can look at using other APIs to do it, e.g. creating your own timer which 
> interrupts the thread doing the read.
> 
> Jifl
> -- 
> eCosCentric    http://www.eCosCentric.com/    The eCos and RedBoot experts
>  >>>>> Visit us in booth 2527 at the Embedded Systems Conference 2004 <<<<<
> March 30 - April 1, San Francisco http://www.esconline.com/electronicaUSA/
> --["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine
> 


______________________________________________________________________________
Ein Grund zum Feiern: Die PC Praxis ermittelt zwischen 10 grossen
Mailprovidern WEB.DE FreeMail als Testsieger http://f.web.de/?mc=021190


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]