00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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 }