public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
* result=read(fd,buffer,200);
@ 2004-07-20 13:12 Sayang Oin
  2004-07-20 15:41 ` result=read(fd,buffer,200); Gerald Emig
  0 siblings, 1 reply; 3+ messages in thread
From: Sayang Oin @ 2004-07-20 13:12 UTC (permalink / raw)
  To: linux-serial

Hello,

I would like to read for example 200 bytes from my UART device throught the 
serial port.

I use

result=read(fd,buffer,200);

I don't know why the result always lesser then 200 bytes.

my open_port  is like this:

int open_port ()
{

  struct termios options, oldtio;

  int fd;

  fd = open (COM,O_RDWR | O_NOCTTY );


if (fd < 0)
{
  fprintf(stderr, "Open_port: unable to open %s\n", COM);
  exit (1);
}
else
{
  fcntl (fd, F_SETFL, FNDELAY);
  printf("\nopen_port: 
%s,%s,%d,%d,%s\n",COM,BAUD,stopbits,datenbits,PARITY);
}

bzero(&options, sizeof(options));


if(!strcmp(BAUD,"B9600"))
   {
	cfsetispeed (&options, B9600);
	cfsetospeed (&options, B9600);
   }
if(!strcmp(BAUD,"B19200"))
   {
	cfsetispeed (&options, B19200);
	cfsetospeed (&options, B19200);
   }
if(!strcmp(BAUD,"B38400"))
   {
	cfsetispeed (&options, B38400);
	cfsetospeed (&options, B38400);
   }
if(!strcmp(BAUD,"B57600"))
   {
	cfsetispeed (&options, B57600);
	cfsetospeed (&options, B57600);
   }
if(!strcmp(BAUD,"B115200"))
   {
	cfsetispeed (&options, B115200);
	cfsetospeed (&options, B115200);
   }



switch(stopbits)
{
   case 1:
    options.c_cflag &= ~CSTOPB;
    break;
   case 2:
    options.c_cflag |= CSTOPB;
    break;
}

options.c_cflag &= ~CSIZE;
switch(datenbits)
{
  case 5:
    options.c_cflag |= CS5;
    break;
  case 6:
    options.c_cflag |= CS6;
    break;
  case 7:
    options.c_cflag |= CS7;
    break;
  case 8:
    options.c_cflag |= CS8;
    break;
}

if(!strcmp(PARITY,"even"))
             {
	      options.c_cflag |= PARENB;
	      options.c_cflag &= ~PARODD;
             }
else if(!strcmp(PARITY,"odd"))
             {
	      options.c_cflag |= PARENB;
	      options.c_cflag |= PARODD;
             }
else if(!strcmp(PARITY,"no"))
             {
	      options.c_cflag &= ~PARENB;
             }

options.c_cflag &= ~CRTSCTS;


options.c_cflag |= (CLOCAL | CREAD);

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

cfmakeraw (&options);

tcflush(fd, TCIFLUSH);
tcsetattr (fd, TCSAFLUSH, &options);

return fd;
}


Thanks for any advice..

Sayangoin

_________________________________________________________________
MSN Toolbar – kostenloser Pop-Up Blocker – Jetzt herunterladen 
http://toolbar.msn.de Jetzt kostenlos downloaden!


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-07-20 17:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-20 13:12 result=read(fd,buffer,200); Sayang Oin
2004-07-20 15:41 ` result=read(fd,buffer,200); Gerald Emig
2004-07-20 17:09   ` result=read(fd,buffer,200); Jan-Benedict Glaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox