Results 1 to 1 of 1
Hello all,
I am trying to run a program which communicates to other system through serial port. I have code like below where i am receiving a steam of characters ...
- 01-05-2011 #1Just Joined!
- Join Date
- Oct 2010
- Posts
- 11
Serial port stops
Hello all,
I am trying to run a program which communicates to other system through serial port. I have code like below where i am receiving a steam of characters of size 10 everytime. It works perfectly for some amount of time say (10 Min.) but after that it stops sending signals or receiving signals.
BAUD = B9600;
DATABITS = CS8;
//Changed by Prasad, stopbit was 0 previousely now it is 1
STOPBITS = 1;
PARITYON = 0;
PARITY = 0;
fd = open(port_id, O_RDWR | O_NOCTTY | O_NONBLOCK );
if(fd < 0)
{
perror(port_id);
exit(-1);
}
else{
printf("Port open %d\n", fd); }
// Signal handling
st_l_saio.sa_handler = signal_handler_IO;
// saio.sa_mask = 0;
st_l_saio.sa_flags = 0;
st_l_saio.sa_restorer = NULL;
sigaction(SIGIO,&st_l_saio,NULL);
fcntl(fd, F_SETOWN, getpid());
/* Make the file descriptor asynchronous (the manual page says only
O_APPEND and O_NONBLOCK, will work with F_SETFL...) */
fcntl(fd, F_SETFL, FASYNC);
tcgetattr(fd, &st_l_termios_old);
st_l_termios_new.c_cflag = B9600 | DATABITS | STOPBITS | PARITYON | PARITY | CREAD | CLOCAL;
st_l_termios_new.c_cflag &= ~CRTSCTS; //Chaged by prasad CRTSCTS was in the above line with all other parameters. Now removed.
// st_l_termios_new.c_lflag = 0;
// st_l_termios_new.c_oflag = 0;
// Input options
//st_l_termios_new.c_iflag = IGNPAR | IXON | IXOFF | IXANY;
st_l_termios_new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
st_l_termios_new.c_oflag &= ~OPOST;
st_l_termios_new.c_iflag = IGNPAR;
st_l_termios_new.c_cc[VMIN] = 10;
st_l_termios_new.c_cc[VTIME] = 0;
//IGNPAR | IGNBRK
// setting New attributes
tcflush(fd, TCIFLUSH); // Flush Input output buffer
tcsetattr(fd, TCSANOW, &st_l_termios_new); // TCSANOW: Apply changes immidtly.
tcflush(fd, TCOFLUSH);
tcflush(fd, TCIFLUSH);
// Toggle DTR if default not open
ioctl(fd, TIOCMGET, &status);
status &= ~TIOCM_DTR;
ioctl(fd, TIOCMSET, &status);
Any help on this appreciated.
Prasad


Reply With Quote