drivers/cfontz/cfontz_unix.c

00001 /*
00002  * Copyright Ian Burnett 2005, 2006.
00003  *
00004  * This file is part of Ian's Interactive LCD controller (IILC).
00005  * 
00006  * IILC is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU General Public License as published by the Free
00008  * Software Foundation; either version 2 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * IILC is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00014  * for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with IILC; if not, write to the Free Software Foundation, Inc.,
00018  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
00019  */
00020 
00021 #include <dlfcn.h>
00022 #include <errno.h>
00023 #include <fcntl.h>
00024 #include <pthread.h>
00025 #include <string.h>
00026 #include <termios.h>
00027 #include <time.h>
00028 #include <unistd.h>
00029 #include <sys/select.h>
00030 #include <sys/time.h>
00031 
00032 #include "trace.h"
00033 #include "cfontz.h"
00034 
00035 
00036 
00037 #define IILC_MODULE MODULE_TYPE_APP
00038 
00039 
00040 int cfontz_InitDevice(LP_CFONTZ_DEV_INSTANCE pInst)
00041 {
00042     int rc = 0;
00043 
00044     struct termios portset; 
00045 
00046     IILC_TRACE_ENTRY(IILC_MODULE, T_cfontz_InitDevice_unix);
00047 
00048     /* Open the USB serial port */
00049     pInst->Device = open(pInst->pszPort, O_RDWR | O_NOCTTY | O_NDELAY);
00050     if (pInst->Device == -1) {
00051         traceError(IILC_TRACE_CONTEXT, "Could not open port [%s]: %s (%d)", 
00052             pInst->pszPort, strerror(errno), errno);
00053         rc = 1;
00054         goto end_of_function;
00055     }
00056 
00057     if (tcgetattr(pInst->Device, &portset) == -1) {
00058         traceDebug(IILC_TRACE_CONTEXT, "tcgetattr() failed: %s", strerror(errno));
00059         rc = 1;
00060         goto end_of_function;
00061     }
00062 
00063     cfmakeraw(&portset);
00064     portset.c_cflag |= 0;
00065     cfsetispeed(&portset, B115200);
00066     cfsetospeed(&portset, B115200);
00067     if (tcsetattr(pInst->Device, TCSANOW, &portset) == -1) {
00068         printf("tcsetattr() failed: %s\n", strerror(errno));
00069         rc = 1;
00070         goto end_of_function;
00071     }
00072 
00073 end_of_function:
00074 
00075     IILC_TRACE_EXIT_RC(rc);
00076     return rc;
00077 }

Generated on Mon Jul 17 01:36:11 2006 for IILC by  doxygen 1.4.6