drivers/cfontz/cfontz_w32.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 "trace.h"
00022 
00023 #include "cfontz.h"
00024 
00025 #define IILC_MODULE MODULE_TYPE_PACKET
00026 
00027 
00028 int cfontz_InitDevice(LP_CFONTZ_DEV_INSTANCE pInst)
00029 {
00030     int rc = 0;
00031 
00032     DCB          dcb;
00033     COMMTIMEOUTS our_timeouts;
00034 
00035     IILC_TRACE_ENTRY(IILC_MODULE, T_cfontz_InitDevice_w32);
00036 
00037     /* Open the USB serial port */
00038     pInst->Device = CreateFile(pInst->pszPort, GENERIC_READ | GENERIC_WRITE,
00039         0, NULL, OPEN_EXISTING, 0, NULL);
00040 
00041     if (pInst->Device == INVALID_HANDLE_VALUE) {
00042         traceDebug(IILC_TRACE_CONTEXT, "Could not open port: %s", strerror(errno));
00043         rc = 1;
00044         goto end_of_function;
00045     }
00046     
00047     /*
00048      * Omit the call to SetupComm to use the default queue sizes.
00049      * Get the current configuration.
00050      */
00051     rc = GetCommState(pInst->Device, &dcb);
00052     if (!rc) {
00053         traceDebug(IILC_TRACE_CONTEXT, "Could not get comm state");
00054         goto end_of_function;
00055     }
00056 
00057     /* Fill in the DCB: baud=115200, 8 data bits, no parity, 1 stop bit. */
00058     dcb.BaudRate = 115200;
00059     dcb.ByteSize = 8;
00060     dcb.Parity = NOPARITY;
00061     dcb.StopBits = ONESTOPBIT;
00062     dcb.fRtsControl = RTS_CONTROL_ENABLE;
00063     dcb.fDtrControl = DTR_CONTROL_ENABLE; 
00064     dcb.fAbortOnError = FALSE; 
00065     
00066     rc = SetCommState(pInst->Device, &dcb);
00067     if (!rc) {
00068         traceDebug(IILC_TRACE_CONTEXT, "Could not set comm state");
00069         goto end_of_function;
00070     }
00071 
00072     if (GetCommTimeouts(pInst->Device, &our_timeouts) != TRUE) {
00073         traceDebug(IILC_TRACE_CONTEXT, "Could not get comm timeouts");
00074         goto end_of_function;
00075     }
00076 
00077     /* 9600 is 1 byte per mS. Set it to 2 mS so the read will stay
00078      * as long as data is coming in. Will wait at least 100mS for
00079      * the 635 to respond.
00080      */
00081     our_timeouts.ReadIntervalTimeout        = 2000;
00082     our_timeouts.ReadTotalTimeoutMultiplier = 2000;  /* 1 second */
00083     our_timeouts.ReadTotalTimeoutConstant   = 2000;
00084 
00085     if (SetCommTimeouts(pInst->Device, &our_timeouts) != TRUE) {
00086         traceDebug(IILC_TRACE_CONTEXT, "Could not set comm timeouts");
00087         goto end_of_function;
00088     }
00089 
00090 end_of_function:
00091 
00092     IILC_TRACE_EXIT_RC(rc);
00093     return rc;
00094 }
00095 

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