00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
00049
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
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
00078
00079
00080
00081 our_timeouts.ReadIntervalTimeout = 2000;
00082 our_timeouts.ReadTotalTimeoutMultiplier = 2000;
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