From: Bahadir Karuv <bahkar@bcacademies.bergen.org>
To: linux-serial@vger.kernel.org
Subject: Newbie problem
Date: Thu, 25 Apr 2002 11:58:39 -0400 [thread overview]
Message-ID: <3CC827AE.F7650476@bcacademies.bergen.org> (raw)
Hello All,
I am trying to have to computers communicate over the serial port.
The program below is modified from "Serial Programming Guide for Posix
operating Systems"
I am geting the following output when I send "Testing123" over the
serial port from the second computer
opened 3
just sent Hello
got back - Hello
just sent Hello
got back - HelloTesting123
just sent Hello
got back - Hello
First computer is getting the string echoed back to itself after it
sends "Hello".
What am I doing wrong?
Thanks and regards!
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h>
int main(void) /* Serial port */
{
time_t tsec;
int fd;
struct termios options;
char buffer[255];
char *bufptr;
int nbytes;
char *message="Hello";
/* open the port */
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
//fcntl(fd, F_SETFL, FNDELAY);
printf("opened %u\n",fd);
/* options */
tcgetattr(fd, &options);
options.c_cflag |= (CLOCAL | CREAD);
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_oflag &= ~OPOST;
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 10;
tcsetattr(fd, TCSANOW, &options);
/* read characters into our string buffer until CR or NL */
while(1){
write(fd, message,strlen(message));
printf("just sent %s\n",message);
tsec=time(NULL);
while(time(NULL)-tsec<1);
bufptr = buffer;
buffer[0]='\0';
while ((nbytes = read(fd, bufptr, bufptr-buffer + sizeof(buffer)-1)) >
0)
{
bufptr += nbytes;
if (bufptr[-1] == '\n' || bufptr[-1] == '\r')
{ printf("break\n");break;}
}
if (buffer!=bufptr){
*(bufptr) = '\0';
printf("got back - %s\n",buffer);
}
}
close(fd);
}
next reply other threads:[~2002-04-25 15:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-25 15:58 Bahadir Karuv [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-07-28 7:20 Newbie problem Insitu
2007-07-28 8:01 ` Junio C Hamano
2007-07-28 8:50 ` Insitu
2003-02-17 8:49 newbie problem Eugene Joubert
2003-02-17 10:48 ` Chris Barnes
2003-02-17 7:43 Chris Barnes
2003-02-17 8:09 ` Joel Newkirk
2003-02-17 10:31 ` Chris Barnes
2003-02-17 8:25 ` Ralf Spenneberg
2003-02-20 11:39 ` Eric Constantineau
2003-02-17 9:00 ` Ralf Spenneberg
[not found] ` <1045470029.2231.54.camel@kermit.spenneberg.de>
[not found] ` <1045477595.21053.2.camel@billybob.back2front.homelinux.org>
2003-02-17 10:27 ` Ralf Spenneberg
2002-04-25 17:19 Newbie problem Ed Vance
2002-04-25 17:37 ` Bahadir Karuv
2002-04-25 16:53 Ed Vance
2002-04-25 17:12 ` Bahadir Karuv
2001-07-24 21:17 Frank Akujobi
2001-07-24 21:34 ` Joel Jaeggli
2001-07-24 21:36 ` Stephen M. Williams
2001-07-24 21:36 ` Paul G. Allen
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=3CC827AE.F7650476@bcacademies.bergen.org \
--to=bahkar@bcacademies.bergen.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.