00001
00002
00003
00004
00005
00006
00007
00008 #include <fcntl.h>
00009 #include <termios.h>
00010 #include <stdio.h>
00011
00012 namespace rwil {
00013 namespace SerialOp {
00014 int fd = 0;
00015
00016
00017
00018
00019
00020
00021 void
00022 open_port(void)
00023 {
00024
00025
00026
00027 fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
00028 if (fd == -1)
00029 {
00030
00031
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
00063 options.c_iflag &= ~(IXON | IXOFF | IXANY);
00064
00065
00066 options.c_oflag &= ~OPOST;
00067
00068 tcsetattr(fd, TCSAFLUSH, &options);
00069 fcntl(fd, F_SETFL, FNDELAY);
00070 }
00071 }
00072
00073 }