Data acquisition from a device through serial port in linux
I have to read and write data frames from & to an electronic device.I am using C for establishing serial port communication with the device.
I have successfully implemented writing to the device.I sent data using this
code patch
fd = open(COMPORT,O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(fd,F_SETFL,0);
tcgetattr(fd,&options);
cfsetospeed(&option,B9600);
cfsetispeed(&option,B9600);
options.c_cflag |= ( CLOCAL | CREAD );
options.c_cflag &= PARENB;
options.c_cflag &= ~PARODD;
options.c_cflag &= ~CSTOP;
options.c_cflag &= ~CSIZE;
options.c_cflag &= ~CRTSCTS;
options.c_cflag |= CS8;
options.c_oflag &= ~OPOST;
options.c_cc[VMIN]=1;
options.c_cc[VTIME]=0;
tcsetattr(fd,TCSANOW,&options);
tcflush(fd,TCIOFLUSH);
for(i=0;i<=7;i++)
n = write(fd,&buff1[i],2);
/*
for(i=0;i<=7;i++)
n = read(fd,&buff3[i],1);
*/
tcdrain(fd);
close(fd);
return 0;
}
when i remove comments and execute read portion of the patch it doesnot read the data comming from the device
Now i am trying to read from the serial port but no success please help me
Esp............... newbie42
|