From: "Sayang Oin" <sayangoin@hotmail.com>
To: linux-serial@vger.kernel.org
Subject: result=read(fd,buffer,200);
Date: Tue, 20 Jul 2004 15:12:24 +0200 [thread overview]
Message-ID: <BAY15-F17edoJhTahSR0009232d@hotmail.com> (raw)
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!
next reply other threads:[~2004-07-20 13:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-20 13:12 Sayang Oin [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BAY15-F17edoJhTahSR0009232d@hotmail.com \
--to=sayangoin@hotmail.com \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox