[ECOS] Non-blocking mode read from serial port

Ali Rodgo alirodgo@web.de
Tue Feb 24 12:13:00 GMT 2004


Hello, 
what i have to do is to read one byte from the serial port send it to the screen and repeat the process.Without VMIN=1 in the programm the read() function doesn't block itself and go to the next step even though no data was read. With the VMIN=1 the read() function block itself each three data and these are always the same, 0 or 128.I don't really know why.The code is quite simple but doesn't work:

/***************************************************************************
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/termios1"
#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 */

/* 8N1*/
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;
}
} 
Any ideas? Something missing in eCos configuration?

Thaks in advance.

Nick Garnett <nickg@ecoscentric.com> schrieb am 24.02.04 10:41:27:
> 
> "Ali Rodgo" <alirodgo@web.de> writes:
> 
> > Thanks a lot, but all of that means that i should use VTIME=0 and
> > VMIN=0 to work propertly or should i change something (the bug
> > explained below) in the termiostty.c in order to use VMIN >0?If that
> > doesn't work how could i read only one byte to one byte from the
> > serial port?
> >
> 
> I'm not sure what you are trying to do. If you want to read a single
> byte, then read a single byte: read(fd,buf,1). If you want the read to
> block while you do it, that is the default. If you want to also wait
> for a timeout then do a select(), then read the byte. If you don't
> want to block then set the O_NONBLOCK flag, select() will still block
> but the read()s won't. Ignore the VTIME/VMIN stuff entirely.
> 
> 
> -- 
> Nick Garnett                    eCos Kernel Architect
> http://www.ecoscentric.com      The eCos and RedBoot experts
> 
> 
> -- 
> Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
> and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
> 


______________________________________________________________________________
Nachrichten, Musik und Spiele schnell und einfach per Quickstart im 
WEB.DE Screensaver - Gratis downloaden: http://screensaver.web.de/?mc=021110


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



More information about the Ecos-discuss mailing list