hai,

i was writing a serial port program and i dont know what went wrong...

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#define BAUDRATE B9600

main()
{
int fd,c, res,STOP;
struct termios oldtio,newtio;
char buf[255];

fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY );
if (fd <0) {perror("/dev/ttyS0"); exit(-1); }

tcgetattr(fd,&oldtio); /* save current serial port settings */
bzero(&newtio, sizeof(newtio)); /* clear struct for new port settings */

newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | ICRNL;
newtio.c_oflag = 0;
newtio.c_lflag = ICANON;


tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);

write(fd,"hello world\n",12);

while (STOP==0)
{
res = read(fd,buf,255);
buf[res]=0;
printf(":%s:%d\n", buf, res);
if (buf[0]=='z') STOP=1;
}

tcsetattr(fd,TCSANOW,&oldtio);

}

i have connected a wire from RxD to TxD of my serial port.

pls help...
_______________________________________________
Indian Libre User Group Cochin Mailing List
http://www.ilug-cochin.org/mailing-list/
http://mail.ilug-cochin.org/mailman/listinfo/mailinglist_ilug-cochin.org
#[email protected]

Reply via email to