Myspace Layouts - eBay - Mobile Phones - Buy Anything On eBay - Mortgage
need a sample code [Archive] - DunLUG - Dunedin Linux Users Group

View Full Version : need a sample code


emb in linux
09-11-2005, 12:33 AM
hai all
This is my first post to this group.I am very much new to embedded
programming .Now i want to write data to com1 and want to read from
com2 .Here i have connected a NULL-MODEM cable in between the two
serial ports.
The following is the code,which i am running on my Linux Box.
I am getting the return value from read as -1.

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>

main()
{
int fd[2],n;
char buff[4];

fd[0]=open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_NDELAY);
fd[1]=open("/dev/ttyS1",O_RDWR | O_NOCTTY | O_NDELAY);
if (fd[0] || fd[1] <= 0)
{
perror("open_port:Unable to open /dev/ttyS0 or /dev/ttyS1");
abrot();
}

/* Before writing data i am reading the buffer */

fcntl(fd[0],F_SETFL,FNDELAY);
n=read(fd[0],buff,4);
printf("%d",n); /*here i am getting the value of n as -1*/
fputs(buff,stdout);/*here i am getting some garbage values */

fcntl(fd[1],F_SETFL,FNDELAY);/*here i am setting the flags*/
n=read(fd[1],buff,4);
printf("%d",n); /*here i am getting the value of n as -1*/
fputs(buff,stdout);/*here i am getting garbage values */

/* Writing data to com1*/

fcntl(fd,F_SETFL,0);
n=write(fd,"hai\r",4);
printf("write n value is %d\n",n); /* here i am getting the value of
n as 4*/
if (n<=0)
{
fputs ("write() of 4 bytes to com1 is failed!\n",stderr);
abort();
}

/* Reading from the com2*/

fcntl(fd[1],F_SETFL,FNDELAY);
n=read(fd[1],buff,4);
printf("read n value is %s\n",buff);
if (n<=0)
fputs ("read() of 4 bytes from com2 is failed!\n",stderr);
fputs(buff,stdout);

/*Closing the com ports*/

close(fd[0]);
close(fd[1]);
}


the output of the code is :garbage values(for 1st fputs)
n=4
n=-1(printf in read)
read of 4 bytes from com2 is
failed
garbage values(for last fputs)

what might
Hope i explaned clearly.
Thanks in Advance.


With Regards

emb in linux.

Simon Clubley
09-11-2005, 02:33 AM
In article <1131449582.397376.229480@o13g2000cwo.googlegroups. com>, "emb in linux" <haranath.t@gmail.com> writes:
> hai all
> This is my first post to this group.I am very much new to embedded
> programming .Now i want to write data to com1 and want to read from
> com2 .Here i have connected a NULL-MODEM cable in between the two
> serial ports.
> The following is the code,which i am running on my Linux Box.
> I am getting the return value from read as -1.
>

And what does errno/perror() say ?

PS: The code appears to have been typed in (misspelling of abort() as abrot())

Try pasting the _actual_ source code.

Simon.

--
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: The Standard Oil Company of the 21st century

emb in linux
09-11-2005, 07:58 PM
hai
1st of all thanks for your sample code.
i want to check my comports on the same system.i am getting receive
program as "IN SERVER",but not getting the byte.how to acheive
that!what might be the wrong here!
waiting for ur reply
with regards
emb in linux.
>
> emb in linux wrote:
> > hai all
> > This is my first post to this group.I am very much new to embedded
> > programming .Now i want to write data to com1 and want to read from
> > com2 .Here i have connected a NULL-MODEM cable in between the two
> > serial ports.
> > The following is the code,which i am running on my Linux Box.
> > I am getting the return value from read as -1.
>
> I haven't analyzed your code, but hereafter you will find an example
> that works for me. I have separated the sending and the receiving parts
> in two separate processes, each with its own source file and binary. I
> start the receiving part first, and it receives the character from the
> sending part when I start it later on.
>
> Good luck,
>
> Alain
>
> Sending part:
>
> #include <stdio.h> /* Standard input/output definitions */
> #include <string.h> /* String function definitions */
> #include <unistd.h> /* UNIX standard function definitions */
> #include <fcntl.h> /* File control definitions */
> #include <errno.h> /* Error number definitions */
> #include <termios.h> /* POSIX terminal control definitions */
>
>
> int
> main()
> {
> int fd; /* File descriptor for the port */
> struct termios options;
>
> /*
> * Open the first serial port, read/write, no controlling terminal,
> * not care about the Data Carrier Detect signal
> */
> fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
> if (fd == -1)
> {
> /*
> * Could not open the port.
> */
> perror("Unable to open /dev/ttyS0\n");
> }
> else {
> /*
> * Set all flags to 0 for the read call to be blocking!???
> * (according to "Serial Programming Guide for POSIX Operating Systems")
> */
> fcntl(fd, F_SETFL, 0);
>
> /*
> * Get the current options for the port...
> */
> tcgetattr(fd, &options);
>
> /*
> * Set the baud rates to 115200...
> */
> cfsetispeed(&options, B115200);
> cfsetospeed(&options, B115200);
>
> /*
> * Enable the receiver and set local mode...
> */
> options.c_cflag |= (CLOCAL | CREAD);
>
> /*
> * Set the option for 8N1
> */
> options.c_cflag &= ~PARENB;
> options.c_cflag &= ~CSTOPB;
> options.c_cflag &= ~CSIZE;
> options.c_cflag |= CS8;
>
> /*
> * Set the option for raw input
> */
> options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
>
> /*
> * Set the option for raw output
> */
> options.c_oflag &= ~OPOST;
>
> /*
> * Set the new options for the port...
> */
> tcsetattr(fd, TCSANOW, &options);
>
> if (write(fd,"A",1)<0)
> fprintf(stderr,"Write() of 1 byte failed!\n");
> close (fd);
> }
>
> return (0);
> }
>
>
> Receiving part:
>
> #include <stdio.h> /* Standard input/output definitions */
> #include <string.h> /* String function definitions */
> #include <unistd.h> /* UNIX standard function definitions */
> #include <fcntl.h> /* File control definitions */
> #include <errno.h> /* Error number definitions */
> #include <termios.h> /* POSIX terminal control definitions */
>
>
> int
> main()
> {
> int fd; /* File descriptor for the port */
> char *c;
> struct termios options;
>
> /*
> * Open the first serial port, read/write, no controlling terminal,
> * not care about the Data Carrier Detect signal
> */
> fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
> if (fd == -1)
> {
> /*
> * Could not open the port.
> */
> perror("Unable to open /dev/ttyS1\n");
> }
> else {
> /*
> * Set all flags to 0 for the read call to be blocking!???
> * (according to "Serial Programming Guide for POSIX Operating Systems")
> */
> fcntl(fd, F_SETFL, 0);
>
> /*
> * Get the current options for the port...
> */
> tcgetattr(fd, &options);
>
> /*
> * Set the baud rates to 115200...
> */
> cfsetispeed(&options, B115200);
> cfsetospeed(&options, B115200);
>
> /*
> * Enable the receiver and set local mode...
> */
> options.c_cflag |= (CLOCAL | CREAD);
>
> /*
> * Set the option for 8N1
> */
> options.c_cflag &= ~PARENB;
> options.c_cflag &= ~CSTOPB;
> options.c_cflag &= ~CSIZE;
> options.c_cflag |= CS8;
>
> /*
> * Set the option for raw input
> */
> options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
>
> /*
> * Set the option for raw output
> */
> options.c_oflag &= ~OPOST;
>
> /*
> * Set the new options for the port...
> */
> tcsetattr(fd, TCSANOW, &options);
>
> fprintf(stderr,"In server\n");
> if (read(fd,c,1)<1)
> fprintf(stderr,"Read() of 1 byte failed!\n");
> else
> fprintf(stderr,"Received %c\n",*c);
> close (fd);
> }
>
> return (0);
> }
>
> /*
> * seriser
> * 2005, Alain Mosnier
> */
>
> #include <stdio.h> /* Standard input/output definitions */
> #include <string.h> /* String function definitions */
> #include <unistd.h> /* UNIX standard function definitions */
> #include <fcntl.h> /* File control definitions */
> #include <errno.h> /* Error number definitions */
> #include <termios.h> /* POSIX terminal control definitions */
>
>
> int
> main()
> {
> int fd; /* File descriptor for the port */
> char *c;
> struct termios options;
>
> /*
> * Open the first serial port, read/write, no controlling terminal,
> * not care about the Data Carrier Detect signal
> */
> fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
> if (fd == -1)
> {
> /*
> * Could not open the port.
> */
> perror("Unable to open /dev/ttyS1\n");
> }
> else {
> /*
> * Set all flags to 0 for the read call to be blocking!???
> * (according to "Serial Programming Guide for POSIX Operating Systems")
> */
> fcntl(fd, F_SETFL, 0);
>
> /*
> * Get the current options for the port...
> */
> tcgetattr(fd, &options);
>
> /*
> * Set the baud rates to 19200...
> */
> cfsetispeed(&options, B115200);
> cfsetospeed(&options, B115200);
>
> /*
> * Enable the receiver and set local mode...
> */
> options.c_cflag |= (CLOCAL | CREAD);
>
> /*
> * Set the option for 8N1
> */
> options.c_cflag &= ~PARENB;
> options.c_cflag &= ~CSTOPB;
> options.c_cflag &= ~CSIZE;
> options.c_cflag |= CS8;
>
> /*
> * Set the option for raw input
> */
> options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
>
> /*
> * Set the option for raw output
> */
> options.c_oflag &= ~OPOST;
>
> /*
> * Set the new options for the port...
> */
> tcsetattr(fd, TCSANOW, &options);
>
> fprintf(stderr,"In server\n");
> if (read(fd,c,1)<1)
> fprintf(stderr,"Read() of 1 byte failed!\n");
> else
> fprintf(stderr,"Received %c\n",*c);
> close (fd);
> }
>
> return (0);
> }

emb in linux
10-11-2005, 12:04 AM
hai
thanks for your code .
i have acheived my startup task comports.
once again thanks for your help.

with
regards
emb in linux

emb in linux
11-11-2005, 06:41 PM
hi
i am able to read and write a string from and to com-ports and i am
unable to read a muti strings(sentence).how can i do that?
thanks in advance.

with
regards
emb
in linux
Alain Mosnier wrote:
> Hi,
>
> emb in linux wrote:
> > hai all
> > This is my first post to this group.I am very much new to embedded
> > programming .Now i want to write data to com1 and want to read from
> > com2 .Here i have connected a NULL-MODEM cable in between the two
> > serial ports.
> > The following is the code,which i am running on my Linux Box.
> > I am getting the return value from read as -1.
>
> I haven't analyzed your code, but hereafter you will find an example
> that works for me. I have separated the sending and the receiving parts
> in two separate processes, each with its own source file and binary. I
> start the receiving part first, and it receives the character from the
> sending part when I start it later on.
>
> Good luck,
>
> Alain
>
> Sending part:
>
> #include <stdio.h> /* Standard input/output definitions */
> #include <string.h> /* String function definitions */
> #include <unistd.h> /* UNIX standard function definitions */
> #include <fcntl.h> /* File control definitions */
> #include <errno.h> /* Error number definitions */
> #include <termios.h> /* POSIX terminal control definitions */
>
>
> int
> main()
> {
> int fd; /* File descriptor for the port */
> struct termios options;
>
> /*
> * Open the first serial port, read/write, no controlling terminal,
> * not care about the Data Carrier Detect signal
> */
> fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
> if (fd == -1)
> {
> /*
> * Could not open the port.
> */
> perror("Unable to open /dev/ttyS0\n");
> }
> else {
> /*
> * Set all flags to 0 for the read call to be blocking!???
> * (according to "Serial Programming Guide for POSIX Operating Systems")
> */
> fcntl(fd, F_SETFL, 0);
>
> /*
> * Get the current options for the port...
> */
> tcgetattr(fd, &options);
>
> /*
> * Set the baud rates to 115200...
> */
> cfsetispeed(&options, B115200);
> cfsetospeed(&options, B115200);
>
> /*
> * Enable the receiver and set local mode...
> */
> options.c_cflag |= (CLOCAL | CREAD);
>
> /*
> * Set the option for 8N1
> */
> options.c_cflag &= ~PARENB;
> options.c_cflag &= ~CSTOPB;
> options.c_cflag &= ~CSIZE;
> options.c_cflag |= CS8;
>
> /*
> * Set the option for raw input
> */
> options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
>
> /*
> * Set the option for raw output
> */
> options.c_oflag &= ~OPOST;
>
> /*
> * Set the new options for the port...
> */
> tcsetattr(fd, TCSANOW, &options);
>
> if (write(fd,"A",1)<0)
> fprintf(stderr,"Write() of 1 byte failed!\n");
> close (fd);
> }
>
> return (0);
> }
>
>
> Receiving part:
>
> #include <stdio.h> /* Standard input/output definitions */
> #include <string.h> /* String function definitions */
> #include <unistd.h> /* UNIX standard function definitions */
> #include <fcntl.h> /* File control definitions */
> #include <errno.h> /* Error number definitions */
> #include <termios.h> /* POSIX terminal control definitions */
>
>
> int
> main()
> {
> int fd; /* File descriptor for the port */
> char *c;
> struct termios options;
>
> /*
> * Open the first serial port, read/write, no controlling terminal,
> * not care about the Data Carrier Detect signal
> */
> fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
> if (fd == -1)
> {
> /*
> * Could not open the port.
> */
> perror("Unable to open /dev/ttyS1\n");
> }
> else {
> /*
> * Set all flags to 0 for the read call to be blocking!???
> * (according to "Serial Programming Guide for POSIX Operating Systems")
> */
> fcntl(fd, F_SETFL, 0);
>
> /*
> * Get the current options for the port...
> */
> tcgetattr(fd, &options);
>
> /*
> * Set the baud rates to 115200...
> */
> cfsetispeed(&options, B115200);
> cfsetospeed(&options, B115200);
>
> /*
> * Enable the receiver and set local mode...
> */
> options.c_cflag |= (CLOCAL | CREAD);
>
> /*
> * Set the option for 8N1
> */
> options.c_cflag &= ~PARENB;
> options.c_cflag &= ~CSTOPB;
> options.c_cflag &= ~CSIZE;
> options.c_cflag |= CS8;
>
> /*
> * Set the option for raw input
> */
> options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
>
> /*
> * Set the option for raw output
> */
> options.c_oflag &= ~OPOST;
>
> /*
> * Set the new options for the port...
> */
> tcsetattr(fd, TCSANOW, &options);
>
> fprintf(stderr,"In server\n");
> if (read(fd,c,1)<1)
> fprintf(stderr,"Read() of 1 byte failed!\n");
> else
> fprintf(stderr,"Received %c\n",*c);
> close (fd);
> }
>
> return (0);
> }
>
> /*
> * seriser
> * 2005, Alain Mosnier
> */
>
> #include <stdio.h> /* Standard input/output definitions */
> #include <string.h> /* String function definitions */
> #include <unistd.h> /* UNIX standard function definitions */
> #include <fcntl.h> /* File control definitions */
> #include <errno.h> /* Error number definitions */
> #include <termios.h> /* POSIX terminal control definitions */
>
>
> int
> main()
> {
> int fd; /* File descriptor for the port */
> char *c;
> struct termios options;
>
> /*
> * Open the first serial port, read/write, no controlling terminal,
> * not care about the Data Carrier Detect signal
> */
> fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
> if (fd == -1)
> {
> /*
> * Could not open the port.
> */
> perror("Unable to open /dev/ttyS1\n");
> }
> else {
> /*
> * Set all flags to 0 for the read call to be blocking!???
> * (according to "Serial Programming Guide for POSIX Operating Systems")
> */
> fcntl(fd, F_SETFL, 0);
>
> /*
> * Get the current options for the port...
> */
> tcgetattr(fd, &options);
>
> /*
> * Set the baud rates to 19200...
> */
> cfsetispeed(&options, B115200);
> cfsetospeed(&options, B115200);
>
> /*
> * Enable the receiver and set local mode...
> */
> options.c_cflag |= (CLOCAL | CREAD);
>
> /*
> * Set the option for 8N1
> */
> options.c_cflag &= ~PARENB;
> options.c_cflag &= ~CSTOPB;
> options.c_cflag &= ~CSIZE;
> options.c_cflag |= CS8;
>
> /*
> * Set the option for raw input
> */
> options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
>
> /*
> * Set the option for raw output
> */
> options.c_oflag &= ~OPOST;
>
> /*
> * Set the new options for the port...
> */
> tcsetattr(fd, TCSANOW, &options);
>
> fprintf(stderr,"In server\n");
> if (read(fd,c,1)<1)
> fprintf(stderr,"Read() of 1 byte failed!\n");
> else
> fprintf(stderr,"Received %c\n",*c);
> close (fd);
> }
>
> return (0);
> }

emb in linux
11-11-2005, 07:00 PM
emb in linux wrote:
hi
using fgets i am able to do that.

> hi
> i am able to read and write a string from and to com-ports and i am
> unable to read a muti strings(sentence).how can i do that?
> thanks in advance.
>
> with
> regards
> emb
> in linux
> Alain Mosnier wrote:
> > Hi,
> >
> > emb in linux wrote:
> > > hai all
> > > This is my first post to this group.I am very much new to embedded
> > > programming .Now i want to write data to com1 and want to read from
> > > com2 .Here i have connected a NULL-MODEM cable in between the two
> > > serial ports.
> > > The following is the code,which i am running on my Linux Box.
> > > I am getting the return value from read as -1.
> >
> > I haven't analyzed your code, but hereafter you will find an example
> > that works for me. I have separated the sending and the receiving parts
> > in two separate processes, each with its own source file and binary. I
> > start the receiving part first, and it receives the character from the
> > sending part when I start it later on.
> >
> > Good luck,
> >
> > Alain
> >
> > Sending part:
> >
> > #include <stdio.h> /* Standard input/output definitions */
> > #include <string.h> /* String function definitions */
> > #include <unistd.h> /* UNIX standard function definitions */
> > #include <fcntl.h> /* File control definitions */
> > #include <errno.h> /* Error number definitions */
> > #include <termios.h> /* POSIX terminal control definitions */
> >
> >
> > int
> > main()
> > {
> > int fd; /* File descriptor for the port */
> > struct termios options;
> >
> > /*
> > * Open the first serial port, read/write, no controlling terminal,
> > * not care about the Data Carrier Detect signal
> > */
> > fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
> > if (fd == -1)
> > {
> > /*
> > * Could not open the port.
> > */
> > perror("Unable to open /dev/ttyS0\n");
> > }
> > else {
> > /*
> > * Set all flags to 0 for the read call to be blocking!???
> > * (according to "Serial Programming Guide for POSIX Operating Systems")
> > */
> > fcntl(fd, F_SETFL, 0);
> >
> > /*
> > * Get the current options for the port...
> > */
> > tcgetattr(fd, &options);
> >
> > /*
> > * Set the baud rates to 115200...
> > */
> > cfsetispeed(&options, B115200);
> > cfsetospeed(&options, B115200);
> >
> > /*
> > * Enable the receiver and set local mode...
> > */
> > options.c_cflag |= (CLOCAL | CREAD);
> >
> > /*
> > * Set the option for 8N1
> > */
> > options.c_cflag &= ~PARENB;
> > options.c_cflag &= ~CSTOPB;
> > options.c_cflag &= ~CSIZE;
> > options.c_cflag |= CS8;
> >
> > /*
> > * Set the option for raw input
> > */
> > options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
> >
> > /*
> > * Set the option for raw output
> > */
> > options.c_oflag &= ~OPOST;
> >
> > /*
> > * Set the new options for the port...
> > */
> > tcsetattr(fd, TCSANOW, &options);
> >
> > if (write(fd,"A",1)<0)
> > fprintf(stderr,"Write() of 1 byte failed!\n");
> > close (fd);
> > }
> >
> > return (0);
> > }
> >
> >
> > Receiving part:
> >
> > #include <stdio.h> /* Standard input/output definitions */
> > #include <string.h> /* String function definitions */
> > #include <unistd.h> /* UNIX standard function definitions */
> > #include <fcntl.h> /* File control definitions */
> > #include <errno.h> /* Error number definitions */
> > #include <termios.h> /* POSIX terminal control definitions */
> >
> >
> > int
> > main()
> > {
> > int fd; /* File descriptor for the port */
> > char *c;
> > struct termios options;
> >
> > /*
> > * Open the first serial port, read/write, no controlling terminal,
> > * not care about the Data Carrier Detect signal
> > */
> > fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
> > if (fd == -1)
> > {
> > /*
> > * Could not open the port.
> > */
> > perror("Unable to open /dev/ttyS1\n");
> > }
> > else {
> > /*
> > * Set all flags to 0 for the read call to be blocking!???
> > * (according to "Serial Programming Guide for POSIX Operating Systems")
> > */
> > fcntl(fd, F_SETFL, 0);
> >
> > /*
> > * Get the current options for the port...
> > */
> > tcgetattr(fd, &options);
> >
> > /*
> > * Set the baud rates to 115200...
> > */
> > cfsetispeed(&options, B115200);
> > cfsetospeed(&options, B115200);
> >
> > /*
> > * Enable the receiver and set local mode...
> > */
> > options.c_cflag |= (CLOCAL | CREAD);
> >
> > /*
> > * Set the option for 8N1
> > */
> > options.c_cflag &= ~PARENB;
> > options.c_cflag &= ~CSTOPB;
> > options.c_cflag &= ~CSIZE;
> > options.c_cflag |= CS8;
> >
> > /*
> > * Set the option for raw input
> > */
> > options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
> >
> > /*
> > * Set the option for raw output
> > */
> > options.c_oflag &= ~OPOST;
> >
> > /*
> > * Set the new options for the port...
> > */
> > tcsetattr(fd, TCSANOW, &options);
> >
> > fprintf(stderr,"In server\n");
> > if (read(fd,c,1)<1)
> > fprintf(stderr,"Read() of 1 byte failed!\n");
> > else
> > fprintf(stderr,"Received %c\n",*c);
> > close (fd);
> > }
> >
> > return (0);
> > }
> >
> > /*
> > * seriser
> > * 2005, Alain Mosnier
> > */
> >
> > #include <stdio.h> /* Standard input/output definitions */
> > #include <string.h> /* String function definitions */
> > #include <unistd.h> /* UNIX standard function definitions */
> > #include <fcntl.h> /* File control definitions */
> > #include <errno.h> /* Error number definitions */
> > #include <termios.h> /* POSIX terminal control definitions */
> >
> >
> > int
> > main()
> > {
> > int fd; /* File descriptor for the port */
> > char *c;
> > struct termios options;
> >
> > /*
> > * Open the first serial port, read/write, no controlling terminal,
> > * not care about the Data Carrier Detect signal
> > */
> > fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
> > if (fd == -1)
> > {
> > /*
> > * Could not open the port.
> > */
> > perror("Unable to open /dev/ttyS1\n");
> > }
> > else {
> > /*
> > * Set all flags to 0 for the read call to be blocking!???
> > * (according to "Serial Programming Guide for POSIX Operating Systems")
> > */
> > fcntl(fd, F_SETFL, 0);
> >
> > /*
> > * Get the current options for the port...
> > */
> > tcgetattr(fd, &options);
> >
> > /*
> > * Set the baud rates to 19200...
> > */
> > cfsetispeed(&options, B115200);
> > cfsetospeed(&options, B115200);
> >
> > /*
> > * Enable the receiver and set local mode...
> > */
> > options.c_cflag |= (CLOCAL | CREAD);
> >
> > /*
> > * Set the option for 8N1
> > */
> > options.c_cflag &= ~PARENB;
> > options.c_cflag &= ~CSTOPB;
> > options.c_cflag &= ~CSIZE;
> > options.c_cflag |= CS8;
> >
> > /*
> > * Set the option for raw input
> > */
> > options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
> >
> > /*
> > * Set the option for raw output
> > */
> > options.c_oflag &= ~OPOST;
> >
> > /*
> > * Set the new options for the port...
> > */
> > tcsetattr(fd, TCSANOW, &options);
> >
> > fprintf(stderr,"In server\n");
> > if (read(fd,c,1)<1)
> > fprintf(stderr,"Read() of 1 byte failed!\n");
> > else
> > fprintf(stderr,"Received %c\n",*c);
> > close (fd);
> > }
> >
> > return (0);
> > }

emb in linux
14-11-2005, 12:04 AM
hello Alain
can i do this more interactivelly.
i did the following excercises.
1.i have open a port and a send a byte then closed it .By using
receive program i opened other port read the charecter .(in between
null modem cable is there)
2.same as above with string.
3.same as above with mutiple strings(sentence)

now i want do this little bit interactivelly.
i will open ttyS0 and give a byte from keyboard and the same byte i
have to recive from ttyS1 without closing ttyS0.here is it possible!
if u have any suggesstions please help me out.
thanks in advance.


with regards

emb in linux.

Alain Mosnier
14-11-2005, 10:23 PM
Hi,

emb in linux wrote:
> hello Alain
> can i do this more interactivelly.
> i did the following excercises.
> 1.i have open a port and a send a byte then closed it .By using
> receive program i opened other port read the charecter .(in between
> null modem cable is there)
> 2.same as above with string.
> 3.same as above with mutiple strings(sentence)
>
> now i want do this little bit interactivelly.
> i will open ttyS0 and give a byte from keyboard and the same byte i
> have to recive from ttyS1 without closing ttyS0.here is it possible!
> if u have any suggesstions please help me out.
> thanks in advance.
>
A I said in my answer to the email to sent me directly:

To be honest I'm not sure whether I will have the time to help you out.
My advice is to post your code on the mailing list and ask questions as
specific as possible. Attach printouts from your program too. I guess if
you post your code, explain what you expect, and also post what you get
(exact printout from your program), people on the list will help you
out. On the other hand, I don't think you should expect that people will
give you code to answer your questions. In my case, you were lucky that
I had a litle sample at hand when I read your message.

Best regards,

Alain