problems accesing serial port
hii..everybody...i'm tryin to acess serial port.I'm using POSIX based commands...i'm able to send some data..but not able to read anything....read function returns -1...which i thnk says dat..read is not workin....plzz help me out...i've pasted my code here
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include<stdio.h>
#include<string.h>
#include<errno.h>
int main()
{
int s;
char port_name[] = "/dev/ttyS0";
char buff[14];
struct termios at;
int x=0,i,y;
char *input;
//----------------------------------------------------------
s = open(port_name, O_RDWR | O_NOCTTY | O_NDELAY);
//----------------------------------------------------------
//struct termios at
tcgetattr(s,&at);
cfsetispeed(&at,B9600);
cfsetospeed(&at,B9600);
at.c_cflag |=(CLOCAL|CREAD);
at.c_cflag &=~(IXON|IXOFF|IXANY);
at.c_cflag &= ~CRTSCTS;
//
tcsetattr(s,TCSANOW,&at);
at.c_cflag &=~(ICANON|ECHO|ECHOE|ISIG);
at.c_cflag &=~PARENB;
at.c_cflag &=~CSTOPB;
at.c_cflag &=~CSIZE;
at.c_cflag |= CS8;
x=write(s,"FFFFFFFFFFFFFF",14);
printf("%d\n",x);
fcntl(s,F_SETFL,FNDELAY);
y=read(s,buff,14);
printf("%d\n",y);
printf("%s\n",buff);
printf("failed!!!");
tcflush(s, TCOFLUSH);
tcflush(s, TCIFLUSH);
close(s);
s = -1;
return 0;
}
pllzz help me out...........!!!!!!!!!1
|