TTY_HANDLE _opentty(char *tty) { TTY_HANDLE fd; #ifdef WIN32 fd = CreateFile(tty, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, NULL, NULL); // We need to set up the port DCB config; // Get current config BOOL fSuccess = GetCommState(fd, &config); // Set up struct config.BaudRate = 115200; config.fBinary = TRUE; config.fParity = FALSE; config.fDtrControl = DTR_CONTROL_DISABLE; config.fDsrSensitivity = FALSE; config.fInX = FALSE; config.fOutX = FALSE; config.fErrorChar = FALSE; config.fNull = FALSE; config.fRtsControl = RTS_CONTROL_DISABLE; config.fAbortOnError = FALSE; config.ByteSize = 8; config.Parity = NOPARITY; config.StopBits = ONESTOPBIT; // Set config SetCommState(fd, &config); #endif #ifdef UNIX struct termios tios; fd = open(tty, O_RDWR | O_NOCTTY); if (fd == -1) { perror("Could not open socket!"); exit(1); } bzero(&tios, sizeof(termios)); tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD; tios.c_iflag = IGNPAR; tios.c_oflag = 0; tios.c_lflag = 0; tios.c_cc[VINTR] = 0; tios.c_cc[VQUIT] = 0; tios.c_cc[VERASE] = 0; tios.c_cc[VKILL] = 0; tios.c_cc[VEOF] = 0; tios.c_cc[VTIME] = 0; tios.c_cc[VSWTC] = 0; tios.c_cc[VSTART] = 0; tios.c_cc[VSTOP] = 0; tios.c_cc[VSUSP] = 0; tios.c_cc[VEOL] = 0; tios.c_cc[VREPRINT] = 0; tios.c_cc[VDISCARD] = 0; tios.c_cc[VWERASE] = 0; tios.c_cc[VLNEXT] = 0; tios.c_cc[VEOL2] = 0; tios.c_cc[VMIN] = 0; tcflush(fd, TCIFLUSH); tcsetattr(fd, TCSANOW, &tios); #endif #ifdef MAC_OSX //TODO: Write #endif return fd; }