/* Open a terminal port at the designated speed. Used for IEEE 488 control. Return a filedescripter. Other things are also set: See the code for comments; the input is very "raw", which we need for IO with the IEEE 488 */ /*#define _POSIX_SOURCE*/ #include #include #include #include #include #include "definitions.h" #include "rs232.h" int rs232_openport(int *file_descriptor, char *name, speed_t speed) { struct termios term; usleep((unsigned long) 1); if ((*file_descriptor = open(name,O_RDWR)) == -1) { fprintf(stderr,"Unable to open the file_descriptor %s\n",name); fflush(stderr); return FAILURE; } printf("Number we are opened to %d \n",*file_descriptor); fflush(stdout); if (tcgetattr(*file_descriptor, &term) < 0) { fprintf(stderr,"Could not get the file_descriptor %d on device %s\n", *file_descriptor, name); return FAILURE; } if ( 0 != cfsetispeed(&term,(speed_t) speed)) { fprintf(stderr, "Could not set the speed of port %s to the desired value\n", name); return FAILURE; } if ( 0 != cfsetospeed(&term, (speed_t) speed)) { fprintf(stderr, "Could not set the speed of port %s to the desired value\n", name); return FAILURE; } term.c_iflag &= ~IGNCR; /* CR is not deleted from input stream */ term.c_iflag &= ~ICRNL; /* do NOT turn CR into NULL */ term.c_iflag &= ~INLCR; /* do NOT convert NL to CR */ term.c_iflag &= ~INPCK; /* disable parity checking */ /* term.c_iflag &= ~ISTRIP; Do NOT strip parity bits */ term.c_iflag |= ISTRIP; /* Do strip parity bits */ term.c_iflag &= ~IGNBRK; /* Ignore break condition on line */ term.c_iflag &= ~IXON; /* Turn OFF XON/XOFF flow control for input */ term.c_iflag &= ~IXOFF; /* Turn OFF XON/XOFF flow control for output */ term.c_oflag &= ~CRTSCTS;/* Turn OFF RTS/CTS (hardware) flow control */ term.c_cflag |= CLOCAL; /* Ignore modem control lines */ term.c_cflag |= CREAD; /* Enable reading characters */ term.c_cflag &= ~CSTOPB; /* two stop bits */ term.c_cflag |= CS8; /* Set 8 bits per byte */ term.c_cflag &= ~PARENB; /* Disable parity checking */ term.c_cflag &= ~HUPCL; /* Do not terminate on hangup */ term.c_lflag &= ~ICANON; /* Non- canonical mode - "raw" */ term.c_lflag &= ~ECHO; /* Do not echo back to file_descriptor */ term.c_lflag &= ~ISIG; /* NO special characters, like SUSP */ term.c_lflag &= ~IEXTEN; /* NO special characters */ term.c_cc[VMIN]=1; term.c_cc[VTIME]=0; if ( 0 != tcsetattr(*file_descriptor,TCSAFLUSH,&term)){ fprintf(stderr,"Could not set the attributes of file_descriptor %s \n", name); return FAILURE; } return SUCCESS; }