Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

SerialOp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           SerialOp.cpp  -  description
00003                              -------------------
00004     begin                : Thu Sep 6 2001
00005     copyright            : (C) 2001 by 
00006     email                : 
00007  ***************************************************************************/
00008 #include <fcntl.h> /* File control definitions */
00009 #include <termios.h> /* POSIX terminal control definitions */
00010 #include <stdio.h> /* Standard input/output definitions */
00011 
00012 namespace rwil {
00013   namespace SerialOp {
00014     int fd = 0;
00015     /*
00016      * 'open_port()' - Open serial port 1.
00017      *
00018      * Returns the file descriptor on success or -1 on error.
00019      */
00020 
00021     void
00022     open_port(void)
00023     {
00024       //        int fd; /* File descriptor for the port */
00025 
00026 
00027       fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
00028       if (fd == -1)
00029         {
00030           /*
00031            * Could not open the port.
00032            */
00033 
00034           perror("open_port: Unable to open /dev/ttyS0 - ");
00035         }
00036       else
00037         fcntl(fd, F_SETFL, 0);
00038 
00039       return;
00040     }
00041         
00042     void configure_port()
00043     {
00044       struct termios options;
00045         
00046       if(!fd) open_port();
00047 
00048       tcgetattr(fd, &options);
00049       cfsetispeed(&options, B9600);
00050       cfsetospeed(&options, B9600);
00051 
00052       options.c_cflag |= CLOCAL | CREAD;
00053       options.c_cflag &= ~CSIZE;
00054       options.c_cflag |= CS8;
00055       options.c_cflag &= ~PARENB;
00056       options.c_cflag &= ~CSTOPB;
00057         
00058       options.c_cflag &= ~CRTSCTS;
00059 
00060       options.c_lflag &= ~(ICANON | ECHO | ECHOE| ISIG );
00061 
00062       //disable software flow control
00063       options.c_iflag &= ~(IXON | IXOFF | IXANY);
00064 
00065       //disaable output mangling
00066       options.c_oflag &= ~OPOST;
00067 
00068       tcsetattr(fd, TCSAFLUSH, &options);
00069       fcntl(fd, F_SETFL, FNDELAY);
00070     }
00071   }
00072 
00073 }

Generated on Tue Apr 9 13:53:08 2002 for RWIL - Real World Interface Library by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001