public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
* Newbie problem
@ 2002-04-25 15:58 Bahadir Karuv
  0 siblings, 0 replies; 5+ messages in thread
From: Bahadir Karuv @ 2002-04-25 15:58 UTC (permalink / raw)
  To: linux-serial

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);
}




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

* RE: Newbie problem
@ 2002-04-25 16:53 Ed Vance
  2002-04-25 17:12 ` Bahadir Karuv
  0 siblings, 1 reply; 5+ messages in thread
From: Ed Vance @ 2002-04-25 16:53 UTC (permalink / raw)
  To: 'Bahadir Karuv'; +Cc: linux-serial

Hi,

My guess is that the second computer has "echo" enabled so all characters
received are echoed back to the other end. I see you turn echo off in the
program. I am assuming that the program is only running on the first
computer. 

Regards,
Ed

---------------------------------------------------------------- 
Ed Vance              edv@macrolink.com
Macrolink, Inc.       1500 N. Kellogg Dr  Anaheim, CA  92807
----------------------------------------------------------------

-----Original Message-----
From: Bahadir Karuv [mailto:bahkar@bcacademies.bergen.org]
Sent: Thursday, April 25, 2002 8:59 AM
To: linux-serial@vger.kernel.org
Subject: Newbie problem


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);
}



-
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: Newbie problem
  2002-04-25 16:53 Ed Vance
@ 2002-04-25 17:12 ` Bahadir Karuv
  0 siblings, 0 replies; 5+ messages in thread
From: Bahadir Karuv @ 2002-04-25 17:12 UTC (permalink / raw)
  To: Ed Vance, linux-serial

Hi Ed,

Thanks for the speedy response. I thought the same but the first
computer keeps getting whatever it is sending ("Hello") eventhough the
serial cable is disconnected. The program I sent is running on the first
computer.

Thanks again and regards,

Karuv

Ed Vance wrote:

> Hi,
>
> My guess is that the second computer has "echo" enabled so all
> characters
> received are echoed back to the other end. I see you turn echo off in
> the
> program. I am assuming that the program is only running on the first
> computer.
>
> Regards,
> Ed
>
> ----------------------------------------------------------------
> Ed Vance              edv@macrolink.com
> Macrolink, Inc.       1500 N. Kellogg Dr  Anaheim, CA  92807
> ----------------------------------------------------------------
>
> -----Original Message-----
> From: Bahadir Karuv [mailto:bahkar@bcacademies.bergen.org]
> Sent: Thursday, April 25, 2002 8:59 AM
> To: linux-serial@vger.kernel.org
> Subject: Newbie problem
>
> 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);
> }
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-serial" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> *** eSafe scanned this email for malicious content ***
> *** IMPORTANT: Do not open attachments from unrecognized senders  ***
>


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

* RE: Newbie problem
@ 2002-04-25 17:19 Ed Vance
  2002-04-25 17:37 ` Bahadir Karuv
  0 siblings, 1 reply; 5+ messages in thread
From: Ed Vance @ 2002-04-25 17:19 UTC (permalink / raw)
  To: 'Bahadir Karuv'; +Cc: linux-serial

Hi Karuv,

Is it not RS-232 interface? RS-485/422 2-wire will do this because the
transmit and receive pairs are the same pair.

Regards,
Ed

---------------------------------------------------------------- 
Ed Vance              edv@macrolink.com
Macrolink, Inc.       1500 N. Kellogg Dr  Anaheim, CA  92807
----------------------------------------------------------------

-----Original Message-----
From: Bahadir Karuv [mailto:bahkar@bcacademies.bergen.org]
Sent: Thursday, April 25, 2002 10:12 AM
To: Ed Vance; linux-serial@vger.kernel.org
Subject: Re: Newbie problem


Hi Ed,

Thanks for the speedy response. I thought the same but the first
computer keeps getting whatever it is sending ("Hello") eventhough the
serial cable is disconnected. The program I sent is running on the first
computer.

Thanks again and regards,

Karuv

Ed Vance wrote:

> Hi,
>
> My guess is that the second computer has "echo" enabled so all
> characters
> received are echoed back to the other end. I see you turn echo off in
> the
> program. I am assuming that the program is only running on the first
> computer.
>
> Regards,
> Ed
>
> ----------------------------------------------------------------
> Ed Vance              edv@macrolink.com
> Macrolink, Inc.       1500 N. Kellogg Dr  Anaheim, CA  92807
> ----------------------------------------------------------------
>
> -----Original Message-----
> From: Bahadir Karuv [mailto:bahkar@bcacademies.bergen.org]
> Sent: Thursday, April 25, 2002 8:59 AM
> To: linux-serial@vger.kernel.org
> Subject: Newbie problem
>
> 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);
> }
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-serial" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> *** eSafe scanned this email for malicious content ***
> *** IMPORTANT: Do not open attachments from unrecognized senders  ***
>

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

* Re: Newbie problem
  2002-04-25 17:19 Newbie problem Ed Vance
@ 2002-04-25 17:37 ` Bahadir Karuv
  0 siblings, 0 replies; 5+ messages in thread
From: Bahadir Karuv @ 2002-04-25 17:37 UTC (permalink / raw)
  To: Ed Vance, linux-serial

Hi Ed,

Thanks again for replying, I was wearing the mouse button, clicking New
Msg icon.
It is RS232,  Dell Optiplex COM1.
Best regards.

Karuv

Ed Vance wrote:

> Hi Karuv,
>
> Is it not RS-232 interface? RS-485/422 2-wire will do this because the
>
> transmit and receive pairs are the same pair.
>
> Regards,
> Ed
>
> ----------------------------------------------------------------
> Ed Vance              edv@macrolink.com
> Macrolink, Inc.       1500 N. Kellogg Dr  Anaheim, CA  92807
> ----------------------------------------------------------------
>
> -----Original Message-----
> From: Bahadir Karuv [mailto:bahkar@bcacademies.bergen.org]
> Sent: Thursday, April 25, 2002 10:12 AM
> To: Ed Vance; linux-serial@vger.kernel.org
> Subject: Re: Newbie problem
>
> Hi Ed,
>
> Thanks for the speedy response. I thought the same but the first
> computer keeps getting whatever it is sending ("Hello") eventhough the
>
> serial cable is disconnected. The program I sent is running on the
> first
> computer.
>
> Thanks again and regards,
>
> Karuv
>
> Ed Vance wrote:
>
> > Hi,
> >
> > My guess is that the second computer has "echo" enabled so all
> > characters
> > received are echoed back to the other end. I see you turn echo off
> in
> > the
> > program. I am assuming that the program is only running on the first
>
> > computer.
> >
> > Regards,
> > Ed
> >
> > ----------------------------------------------------------------
> > Ed Vance              edv@macrolink.com
> > Macrolink, Inc.       1500 N. Kellogg Dr  Anaheim, CA  92807
> > ----------------------------------------------------------------
> >
> > -----Original Message-----
> > From: Bahadir Karuv [mailto:bahkar@bcacademies.bergen.org]
> > Sent: Thursday, April 25, 2002 8:59 AM
> > To: linux-serial@vger.kernel.org
> > Subject: Newbie problem
> >
> > 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);
> > }
> >
> >
> > -
> > To unsubscribe from this list: send the line "unsubscribe
> > linux-serial" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > *** eSafe scanned this email for malicious content ***
> > *** IMPORTANT: Do not open attachments from unrecognized senders
> ***
> >
> *** eSafe scanned this email for malicious content ***
> *** IMPORTANT: Do not open attachments from unrecognized senders  ***
>


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

end of thread, other threads:[~2002-04-25 17:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-25 17:19 Newbie problem Ed Vance
2002-04-25 17:37 ` Bahadir Karuv
  -- strict thread matches above, loose matches on Subject: below --
2002-04-25 16:53 Ed Vance
2002-04-25 17:12 ` Bahadir Karuv
2002-04-25 15:58 Bahadir Karuv

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