这篇教程C++ tcsetattr函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中tcsetattr函数的典型用法代码示例。如果您正苦于以下问题:C++ tcsetattr函数的具体用法?C++ tcsetattr怎么用?C++ tcsetattr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了tcsetattr函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: canonicalint canonical(struct termios *saved){ //Restaura la configuración original del usuario. return( tcsetattr( 0, TCSADRAIN, saved ) );}
开发者ID:farevalod,项目名称:thehunt,代码行数:4,
示例2: daemon_accept//.........这里部分代码省略......... } int outfd = open(outfile, O_WRONLY); if (outfd <= 0) { PLOGE("outfd daemon %s", outfile); goto done; } int errfd = open(errfile, O_WRONLY); if (errfd <= 0) { PLOGE("errfd daemon %s", errfile); goto done; } int infd = open(infile, O_RDONLY); if (infd <= 0) { PLOGE("infd daemon %s", infile); goto done; } int code; // now fork and run main, watch for the child pid exit, and send that // across the control channel as the response. int child = fork(); if (child < 0) { code = child; goto done; } // if this is the child, open the fifo streams // and dup2 them with stdin/stdout, and run main, which execs // the target. if (child == 0) { close(fd); if (devname != NULL) { int pts = open(devname, O_RDWR); if(pts < 0) { PLOGE("pts"); exit(-1); } struct termios slave_orig_term_settings; // Saved terminal settings tcgetattr(pts, &slave_orig_term_settings); struct termios new_term_settings; new_term_settings = slave_orig_term_settings; cfmakeraw(&new_term_settings); // WHY DOESN'T THIS WORK, FUUUUU new_term_settings.c_lflag &= ~(ECHO); tcsetattr(pts, TCSANOW, &new_term_settings); setsid(); ioctl(pts, TIOCSCTTY, 1); close(infd); close(outfd); close(errfd); close(ptm); errfd = pts; infd = pts; outfd = pts; }#ifdef SUPERUSER_EMBEDEDED if (mount_storage) { mount_emulated_storage(multiuser_get_user_id(daemon_from_uid)); }#endif return run_daemon_child(infd, outfd, errfd, argc, argv); } if (devname != NULL) { // pump ptm across the socket pump_async(infd, ptm); pump(ptm, outfd); } else { close(infd); close(outfd); close(errfd); } // wait for the child to exit, and send the exit code // across the wire. int status; LOGD("waiting for child exit"); if (waitpid(child, &status, 0) > 0) { code = WEXITSTATUS(status); } else { code = -1; }done: write(fd, &code, sizeof(int)); close(fd); LOGD("child exited"); return code;}
开发者ID:Lekensteyn,项目名称:Superuser,代码行数:101,
示例3: close_serial_portint close_serial_port(void){ tcsetattr(ComFd, TCSANOW, &ComTio_Bk); return close(ComFd);}
开发者ID:bokunimowakaru,项目名称:xbeeCoord,代码行数:4,
示例4: phDal4Nfc_uart_open_and_configureNFCSTATUS phDal4Nfc_uart_open_and_configure(pphDal4Nfc_sConfig_t pConfig, void ** pLinkHandle){ int nComStatus; NFCSTATUS nfcret = NFCSTATUS_SUCCESS; int ret; DAL_ASSERT_STR(gComPortContext.nOpened==0, "Trying to open but already done!"); srand(time(NULL)); /* open communication port handle */ gComPortContext.nHandle = open(pConfig->deviceNode, O_RDWR | O_NOCTTY); if (gComPortContext.nHandle < 0) { *pLinkHandle = NULL; return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_DEVICE); } gComPortContext.nOpened = 1; *pLinkHandle = (void*)gComPortContext.nHandle; /* * Now configure the com port */ ret = tcgetattr(gComPortContext.nHandle, &gComPortContext.nIoConfigBackup); /* save the old io config */ if (ret == -1) { /* tcgetattr failed -- it is likely that the provided port is invalid */ *pLinkHandle = NULL; return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_DEVICE); } ret = fcntl(gComPortContext.nHandle, F_SETFL, 0); /* Makes the read blocking (default). */ DAL_ASSERT_STR(ret != -1, "fcntl failed"); /* Configures the io */ memset((void *)&gComPortContext.nIoConfig, (int)0, (size_t)sizeof(struct termios)); /* BAUDRATE: Set bps rate. You could also use cfsetispeed and cfsetospeed. CRTSCTS : output hardware flow control (only used if the cable has all necessary lines. See sect. 7 of Serial-HOWTO) CS8 : 8n1 (8bit,no parity,1 stopbit) CLOCAL : local connection, no modem contol CREAD : enable receiving characters */ gComPortContext.nIoConfig.c_cflag = DAL_BAUD_RATE | CS8 | CLOCAL | CREAD; /* Control mode flags */ gComPortContext.nIoConfig.c_iflag = IGNPAR; /* Input mode flags : IGNPAR Ignore parity errors */ gComPortContext.nIoConfig.c_oflag = 0; /* Output mode flags */ gComPortContext.nIoConfig.c_lflag = 0; /* Local mode flags. Read mode : non canonical, no echo */ gComPortContext.nIoConfig.c_cc[VTIME] = 0; /* Control characters. No inter-character timer */ gComPortContext.nIoConfig.c_cc[VMIN] = 1; /* Control characters. Read is blocking until X characters are read */ /* TCSANOW Make changes now without waiting for data to complete TCSADRAIN Wait until everything has been transmitted TCSAFLUSH Flush input and output buffers and make the change */ ret = tcsetattr(gComPortContext.nHandle, TCSANOW, &gComPortContext.nIoConfig); DAL_ASSERT_STR(ret != -1, "tcsetattr failed"); /* On linux the DTR signal is set by default. That causes a problem for pn544 chip because this signal is connected to "reset". So we clear it. (on windows it is cleared by default). */ ret = ioctl(gComPortContext.nHandle, TIOCMGET, &nComStatus); DAL_ASSERT_STR(ret != -1, "ioctl TIOCMGET failed"); nComStatus &= ~TIOCM_DTR; ret = ioctl(gComPortContext.nHandle, TIOCMSET, &nComStatus); DAL_ASSERT_STR(ret != -1, "ioctl TIOCMSET failed"); DAL_DEBUG("Com port status=%d/n", nComStatus); usleep(10000); /* Mandatory sleep so that the DTR line is ready before continuing */ return nfcret;}
开发者ID:Abocer,项目名称:android-4.2_r1,代码行数:72,
示例5: OpenComms//.........这里部分代码省略......... case 2400: BAUD = B2400; break; case 1800: BAUD = B1800; break; case 1200: BAUD = B1200; break; case 600: BAUD = B600; break; case 300: BAUD = B300; break; case 200: BAUD = B200; break; case 150: BAUD = B150; break; case 134: BAUD = B134; break; case 110: BAUD = B110; break; case 75: BAUD = B75; break; case 50: BAUD = B50; break; default: BAUD = B19200; break; } //end of switch CommPortSpeed if (cfsetispeed(&config, BAUD) < 0 || cfsetospeed(&config, BAUD) < 0) {#else if (cfsetispeed(&config, CommPortSpeed) < 0 || cfsetospeed(&config, CommPortSpeed) < 0) {#endif LoggingFile.mLogFile << "failed to set port speed" << endl; CloseComms(); return; } // // Finally, apply the configuration // if (tcsetattr(fd, TCSAFLUSH, &config) < 0) { LoggingFile.mLogFile << "failed to configure port" << endl; CloseComms(); return; } LoggingFile.mLogFile << "Opened port " << device << endl;}//---------------------------------------------------------------------------void CloseComms(void){ if (fd != -1) { close(fd); fd = -1; LoggingFile.mLogFile << "Closed port" << endl; }}//---------------------------------------------------------------------------void SendToComPort(unsigned long ResponseLength, unsigned char *Buffer){ if (fd != -1) { int written = write(fd, Buffer, ResponseLength); if (written != ResponseLength) { LoggingFile.mLogFile << "serial write failed (" << ResponseLength << ", " << written << ")" << endl; } }}//---------------------------------------------------------------------------void ReceiveFromComPort(void){ unsigned long dwBytesTransferred = 0; char Byte = 0x00; if (fd != -1) { // Loop for waiting for the data. while (read(fd, &Byte, 1) == 1) { HandleMsgByte(Byte); } }}
开发者ID:Inspirati,项目名称:MP_Aerodyn,代码行数:101,
示例6: restorestatic void restore(void){ tcsetattr(STDIN_FILENO, TCSANOW, &term);}
开发者ID:OpenHyperCube,项目名称:dvb-apps,代码行数:4,
示例7: disable_raw void disable_raw() { /* Don't even check the return value as it's too late. */ if (rawmode && tcsetattr(STDIN_FILENO,TCSAFLUSH,&orig_termios) != -1) rawmode = 0; }
开发者ID:gsvslto,项目名称:dfhack,代码行数:6,
示例8: ifint16 XSERDPort::open(uint16 config){ // Don't open NULL name devices if (device_name == NULL) return openErr; // Init variables io_killed = false; quitting = false; // Open port, according to the syntax of the path if (device_name[0] == '|') { // Open a process via ptys if (!open_pty()) goto open_error; } else if (!strcmp(device_name, "midi")) { // MIDI: not yet implemented return openErr; } else { // Device special file fd = ::open(device_name, O_RDWR); if (fd < 0) goto open_error;#if defined(__linux__) // Parallel port? struct stat st; if (fstat(fd, &st) == 0) if (S_ISCHR(st.st_mode)) protocol = ((MAJOR(st.st_rdev) == LP_MAJOR) ? parallel : serial);#elif defined(__FreeBSD__) || defined(__NetBSD__) // Parallel port? struct stat st; if (fstat(fd, &st) == 0) if (S_ISCHR(st.st_mode)) protocol = (((st.st_rdev >> 16) == 16) ? parallel : serial);#endif } // Configure port for raw mode if (protocol == serial || protocol == pty) { if (tcgetattr(fd, &mode) < 0) goto open_error; cfmakeraw(&mode); mode.c_cflag |= HUPCL; mode.c_cc[VMIN] = 1; mode.c_cc[VTIME] = 0; tcsetattr(fd, TCSAFLUSH, &mode); } configure(config); // Start input/output threads input_thread_cancel = false; output_thread_cancel = false; if (sem_init(&input_signal, 0, 0) < 0) goto open_error; if (sem_init(&output_signal, 0, 0) < 0) goto open_error; input_thread_active = (pthread_create(&input_thread, &thread_attr, input_func, this) == 0); output_thread_active = (pthread_create(&output_thread, &thread_attr, output_func, this) == 0); if (!input_thread_active || !output_thread_active) goto open_error; return noErr;open_error: if (input_thread_active) { input_thread_cancel = true;#ifdef HAVE_PTHREAD_CANCEL pthread_cancel(input_thread);#endif pthread_join(input_thread, NULL); sem_destroy(&input_signal); input_thread_active = false; } if (output_thread_active) { output_thread_cancel = true;#ifdef HAVE_PTHREAD_CANCEL pthread_cancel(output_thread);#endif pthread_join(output_thread, NULL); sem_destroy(&output_signal); output_thread_active = false; } if (fd > 0) { ::close(fd); fd = -1; } return openErr;}
开发者ID:habnabit,项目名称:macemu,代码行数:91,
示例9: tcgetattrvoid TurtlebotTeleop::keyLoop(){ char c; // get the console in raw mode tcgetattr(kfd, &cooked); memcpy(&raw, &cooked, sizeof(struct termios)); raw.c_lflag &=~ (ICANON | ECHO); // Setting a new line, then end of file raw.c_cc[VEOL] = 1; raw.c_cc[VEOF] = 2; tcsetattr(kfd, TCSANOW, &raw); puts("Reading from keyboard"); puts("---------------------------"); puts("Use arrow keys to move the turtlebot."); while (ros::ok()) { // get the next event from the keyboard if(read(kfd, &c, 1) < 0) { perror("read():"); exit(-1); } linear_=angular_=0; ROS_DEBUG("value: 0x%02X/n", c); switch(c) { case KEYCODE_L: ROS_DEBUG("LEFT"); angular_ = 1.0; break; case KEYCODE_R: ROS_DEBUG("RIGHT"); angular_ = -1.0; break; case KEYCODE_U: ROS_DEBUG("UP"); linear_ = 0.5; break; case KEYCODE_D: ROS_DEBUG("DOWN"); linear_ = -0.5; break; case KEYCODE_Q: ROS_DEBUG("QUIT"); linear_ = 0.0; angular_ = 0.0; break; } boost::mutex::scoped_lock lock(publish_mutex_); if (ros::Time::now() > last_publish_ + ros::Duration(1.0)) { first_publish_ = ros::Time::now(); } last_publish_ = ros::Time::now(); publish(angular_, linear_); if(c==KEYCODE_Q) quit(SIGINT); } return;}
开发者ID:weiin,项目名称:transporter-project,代码行数:68,
示例10: quitvoid quit(int sig){ tcsetattr(kfd, TCSANOW, &cooked); ros::shutdown(); exit(0);}
开发者ID:weiin,项目名称:transporter-project,代码行数:6,
示例11: Windows//.........这里部分代码省略......... cfsetospeed(&Posix_CommConfig, B19200);#endif break; /*38400 baud*/ case BAUD38400:#ifdef CBAUD Posix_CommConfig.c_cflag&=(~CBAUD); Posix_CommConfig.c_cflag|=B38400;#else cfsetispeed(&Posix_CommConfig, B38400); cfsetospeed(&Posix_CommConfig, B38400);#endif break; /*56000 baud*/ case BAUD56000: TTY_WARNING("QextSerialPort: POSIX does not support 56000 baud operation. Switching to 38400 baud.");#ifdef CBAUD Posix_CommConfig.c_cflag&=(~CBAUD); Posix_CommConfig.c_cflag|=B38400;#else cfsetispeed(&Posix_CommConfig, B38400); cfsetospeed(&Posix_CommConfig, B38400);#endif break; /*57600 baud*/ case BAUD57600:#ifdef CBAUD Posix_CommConfig.c_cflag&=(~CBAUD); Posix_CommConfig.c_cflag|=B57600;#else cfsetispeed(&Posix_CommConfig, B57600); cfsetospeed(&Posix_CommConfig, B57600);#endif break; /*76800 baud*/ case BAUD76800: TTY_PORTABILITY_WARNING("QextSerialPort Portability Warning: Windows and some POSIX systems do not support 76800 baud operation.");#ifdef CBAUD Posix_CommConfig.c_cflag&=(~CBAUD);#ifdef B76800 Posix_CommConfig.c_cflag|=B76800;#else TTY_WARNING("QextSerialPort: QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud."); Posix_CommConfig.c_cflag|=B57600;#endif //B76800#else //CBAUD#ifdef B76800 cfsetispeed(&Posix_CommConfig, B76800); cfsetospeed(&Posix_CommConfig, B76800);#else TTY_WARNING("QextSerialPort: QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud."); cfsetispeed(&Posix_CommConfig, B57600); cfsetospeed(&Posix_CommConfig, B57600);#endif //B76800#endif //CBAUD break; /*115200 baud*/ case BAUD115200:#ifdef CBAUD Posix_CommConfig.c_cflag&=(~CBAUD); Posix_CommConfig.c_cflag|=B115200;#else cfsetispeed(&Posix_CommConfig, B115200); cfsetospeed(&Posix_CommConfig, B115200);#endif break; /*128000 baud*/ case BAUD128000: TTY_WARNING("QextSerialPort: POSIX does not support 128000 baud operation. Switching to 115200 baud.");#ifdef CBAUD Posix_CommConfig.c_cflag&=(~CBAUD); Posix_CommConfig.c_cflag|=B115200;#else cfsetispeed(&Posix_CommConfig, B115200); cfsetospeed(&Posix_CommConfig, B115200);#endif break; /*256000 baud*/ case BAUD256000: TTY_WARNING("QextSerialPort: POSIX does not support 256000 baud operation. Switching to 115200 baud.");#ifdef CBAUD Posix_CommConfig.c_cflag&=(~CBAUD); Posix_CommConfig.c_cflag|=B115200;#else cfsetispeed(&Posix_CommConfig, B115200); cfsetospeed(&Posix_CommConfig, B115200);#endif break; } tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); }}
开发者ID:no3m,项目名称:so2sdr,代码行数:101,
示例12: lock/*!Sets the parity associated with the serial port. The possible values of parity are:/verbatim PAR_SPACE Space Parity PAR_MARK Mark Parity PAR_NONE No Parity PAR_EVEN Even Parity PAR_ODD Odd Parity/endverbatim/noteThis function is subject to the following limitations:/parPOSIX systems do not support mark parity./parPOSIX systems support space parity only if tricked into doing so, and only with fewer than 8 data bits. Use space parity very carefully with POSIX systems.*/void QextSerialPort::setParity(ParityType parity){ QMutexLocker lock(mutex); if (Settings.Parity!=parity) { if (parity==PAR_MARK || (parity==PAR_SPACE && Settings.DataBits==DATA_8)) { } else { Settings.Parity=parity; } } if (isOpen()) { switch (parity) { /*space parity*/ case PAR_SPACE: if (Settings.DataBits==DATA_8) { TTY_PORTABILITY_WARNING("QextSerialPort: Space parity is only supported in POSIX with 7 or fewer data bits"); } else { /*space parity not directly supported - add an extra data bit to simulate it*/ Posix_CommConfig.c_cflag&=~(PARENB|CSIZE); switch(Settings.DataBits) { case DATA_5: Settings.DataBits=DATA_6; Posix_CommConfig.c_cflag|=CS6; break; case DATA_6: Settings.DataBits=DATA_7; Posix_CommConfig.c_cflag|=CS7; break; case DATA_7: Settings.DataBits=DATA_8; Posix_CommConfig.c_cflag|=CS8; break; case DATA_8: break; } tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); } break; /*mark parity - WINDOWS ONLY*/ case PAR_MARK: TTY_WARNING("QextSerialPort: Mark parity is not supported by POSIX."); break; /*no parity*/ case PAR_NONE: Posix_CommConfig.c_cflag&=(~PARENB); tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); break; /*even parity*/ case PAR_EVEN: Posix_CommConfig.c_cflag&=(~PARODD); Posix_CommConfig.c_cflag|=PARENB; tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); break; /*odd parity*/ case PAR_ODD: Posix_CommConfig.c_cflag|=(PARENB|PARODD); tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); break; } }}
开发者ID:no3m,项目名称:so2sdr,代码行数:89,
示例13: ttyResetstatic void /* Reset terminal mode on program exit */ttyReset(void){ if (tcsetattr(STDIN_FILENO, TCSANOW, &ttyOrig) == -1) errExit("tcsetattr");}
开发者ID:duxing2007,项目名称:books-examples,代码行数:6,
示例14: switchint16 XSERDPort::control(uint32 pb, uint32 dce, uint16 code){ switch (code) { case 1: // KillIO io_killed = true; if (protocol == serial) tcflush(fd, TCIOFLUSH); while (read_pending || write_pending) usleep(10000); io_killed = false; return noErr; case kSERDConfiguration: if (configure(ReadMacInt16(pb + csParam))) return noErr; else return paramErr; case kSERDInputBuffer: return noErr; // Not supported under Unix case kSERDSerHShake: set_handshake(pb + csParam, false); return noErr; case kSERDSetBreak: if (protocol == serial) tcsendbreak(fd, 0); return noErr; case kSERDClearBreak: return noErr; case kSERDBaudRate: { if (protocol != serial) return noErr; uint16 rate = ReadMacInt16(pb + csParam); speed_t baud_rate; if (rate <= 50) { rate = 50; baud_rate = B50; } else if (rate <= 75) { rate = 75; baud_rate = B75; } else if (rate <= 110) { rate = 110; baud_rate = B110; } else if (rate <= 134) { rate = 134; baud_rate = B134; } else if (rate <= 150) { rate = 150; baud_rate = B150; } else if (rate <= 200) { rate = 200; baud_rate = B200; } else if (rate <= 300) { rate = 300; baud_rate = B300; } else if (rate <= 600) { rate = 600; baud_rate = B600; } else if (rate <= 1200) { rate = 1200; baud_rate = B1200; } else if (rate <= 1800) { rate = 1800; baud_rate = B1800; } else if (rate <= 2400) { rate = 2400; baud_rate = B2400; } else if (rate <= 4800) { rate = 4800; baud_rate = B4800; } else if (rate <= 9600) { rate = 9600; baud_rate = B9600; } else if (rate <= 19200) { rate = 19200; baud_rate = B19200; } else if (rate <= 38400) { rate = 38400; baud_rate = B38400; } else if (rate <= 57600) { rate = 57600; baud_rate = B57600; } else { // Just for safety in case someone wants a rate between 57600 and 65535 rate = 57600; baud_rate = B57600; } WriteMacInt16(pb + csParam, rate); cfsetispeed(&mode, baud_rate); cfsetospeed(&mode, baud_rate); tcsetattr(fd, TCSANOW, &mode); return noErr; } case kSERDHandshake: case kSERDHandshakeRS232: set_handshake(pb + csParam, true); return noErr; case kSERDMiscOptions: if (protocol != serial) return noErr; if (ReadMacInt8(pb + csParam) & kOptionPreserveDTR) mode.c_cflag &= ~HUPCL; else mode.c_cflag |= HUPCL; tcsetattr(fd, TCSANOW, &mode); return noErr; case kSERDAssertDTR: { if (protocol != serial) return noErr; unsigned int status = TIOCM_DTR;//.........这里部分代码省略.........
开发者ID:habnabit,项目名称:macemu,代码行数:101,
示例15: pty_allocate//.........这里部分代码省略......... error("Could not open /dev/ptc: %.100s", strerror(errno)); return 0; } name = ttyname(*ptyfd); if (!name) fatal("Open of /dev/ptc returns device for which ttyname fails."); strlcpy(namebuf, name, namebuflen); *ttyfd = open(name, O_RDWR | O_NOCTTY); if (*ttyfd < 0) { error("Could not open pty slave side %.100s: %.100s", name, strerror(errno)); close(*ptyfd); return 0; } return 1;#else /* HAVE_DEV_PTS_AND_PTC */#ifdef _UNICOS char buf[64]; int i; int highpty;#ifdef _SC_CRAY_NPTY highpty = sysconf(_SC_CRAY_NPTY); if (highpty == -1) highpty = 128;#else highpty = 128;#endif for (i = 0; i < highpty; i++) { snprintf(buf, sizeof(buf), "/dev/pty/%03d", i); *ptyfd = open(buf, O_RDWR|O_NOCTTY); if (*ptyfd < 0) continue; snprintf(namebuf, namebuflen, "/dev/ttyp%03d", i); /* Open the slave side. */ *ttyfd = open(namebuf, O_RDWR|O_NOCTTY); if (*ttyfd < 0) { error("%.100s: %.100s", namebuf, strerror(errno)); close(*ptyfd); return 0; } return 1; } return 0;#else /* BSD-style pty code. */ char buf[64]; int i; const char *ptymajors = "pqrstuvwxyzabcdefghijklmnoABCDEFGHIJKLMNOPQRSTUVWXYZ"; const char *ptyminors = "0123456789abcdef"; int num_minors = strlen(ptyminors); int num_ptys = strlen(ptymajors) * num_minors; struct termios tio; for (i = 0; i < num_ptys; i++) { snprintf(buf, sizeof buf, "/dev/pty%c%c", ptymajors[i / num_minors], ptyminors[i % num_minors]); snprintf(namebuf, namebuflen, "/dev/tty%c%c", ptymajors[i / num_minors], ptyminors[i % num_minors]); *ptyfd = open(buf, O_RDWR | O_NOCTTY); if (*ptyfd < 0) { /* Try SCO style naming */ snprintf(buf, sizeof buf, "/dev/ptyp%d", i); snprintf(namebuf, namebuflen, "/dev/ttyp%d", i); *ptyfd = open(buf, O_RDWR | O_NOCTTY); if (*ptyfd < 0) continue; } /* Open the slave side. */ *ttyfd = open(namebuf, O_RDWR | O_NOCTTY); if (*ttyfd < 0) { error("%.100s: %.100s", namebuf, strerror(errno)); close(*ptyfd); return 0; } /* set tty modes to a sane state for broken clients */ if (tcgetattr(*ptyfd, &tio) < 0) log("Getting tty modes for pty failed: %.100s", strerror(errno)); else { tio.c_lflag |= (ECHO | ISIG | ICANON); tio.c_oflag |= (OPOST | ONLCR); tio.c_iflag |= ICRNL; /* Set the new modes for the terminal. */ if (tcsetattr(*ptyfd, TCSANOW, &tio) < 0) log("Setting tty modes for pty failed: %.100s", strerror(errno)); } return 1; } return 0;#endif /* CRAY */#endif /* HAVE_DEV_PTS_AND_PTC */#endif /* HAVE_DEV_PTMX */#endif /* HAVE__GETPTY */#endif /* HAVE_OPENPTY */}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:101,
示例16: Dbool XSERDPort::configure(uint16 config){ D(bug(" configure %04x/n", config)); if (protocol != serial) return true; // Set number of stop bits switch (config & 0xc000) { case stop10: mode.c_cflag &= ~CSTOPB; break; case stop20: mode.c_cflag |= CSTOPB; break; default: return false; } // Set parity mode switch (config & 0x3000) { case noParity: mode.c_iflag &= ~INPCK; mode.c_oflag &= ~PARENB; break; case oddParity: mode.c_iflag |= INPCK; mode.c_oflag |= PARENB; mode.c_oflag |= PARODD; break; case evenParity: mode.c_iflag |= INPCK; mode.c_oflag |= PARENB; mode.c_oflag &= ~PARODD; break; default: return false; } // Set number of data bits switch (config & 0x0c00) { case data5: mode.c_cflag = mode.c_cflag & ~CSIZE | CS5; break; case data6: mode.c_cflag = mode.c_cflag & ~CSIZE | CS6; break; case data7: mode.c_cflag = mode.c_cflag & ~CSIZE | CS7; break; case data8: mode.c_cflag = mode.c_cflag & ~CSIZE | CS8; break; } // Set baud rate speed_t baud_rate; switch (config & 0x03ff) { case baud150: baud_rate = B150; break; case baud300: baud_rate = B300; break; case baud600: baud_rate = B600; break; case baud1200: baud_rate = B1200; break; case baud1800: baud_rate = B1800; break; case baud2400: baud_rate = B2400; break; case baud4800: baud_rate = B4800; break; case baud9600: baud_rate = B9600; break; case baud19200: baud_rate = B19200; break; case baud38400: baud_rate = B38400; break; case baud57600: baud_rate = B57600; break; default: return false; } cfsetispeed(&mode, baud_rate); cfsetospeed(&mode, baud_rate); tcsetattr(fd, TCSANOW, &mode); return true;}
开发者ID:habnabit,项目名称:macemu,代码行数:76,
示例17: main//.........这里部分代码省略......... } if (tcgetattr(STDIN_FILENO, &saved_tty) == -1) xwarn(_("terminal setting retrieval")); old_rows = rows; term_size(0); if (!run_once) { initscr(); resizeterm(rows, cols); signal(SIGWINCH, term_size); } signal(SIGINT, sigint_handler); do { struct slab_info *curr; struct slab_stat stats; struct timeval tv; fd_set readfds; char c; int i; memset(&stats, 0, sizeof(struct slab_stat)); if (get_slabinfo(&slab_list, &stats)) { retval = EXIT_FAILURE; break; } if (!run_once && old_rows != rows) { resizeterm(rows, cols); old_rows = rows; } move(0, 0); print_line(" %-35s: %d / %d (%.1f%%)/n" " %-35s: %d / %d (%.1f%%)/n" " %-35s: %d / %d (%.1f%%)/n" " %-35s: %.2fK / %.2fK (%.1f%%)/n" " %-35s: %.2fK / %.2fK / %.2fK/n/n", /* Translation Hint: Next five strings must not * exceed 35 length in characters. */ /* xgettext:no-c-format */ _("Active / Total Objects (% used)"), stats.nr_active_objs, stats.nr_objs, 100.0 * stats.nr_active_objs / stats.nr_objs, /* xgettext:no-c-format */ _("Active / Total Slabs (% used)"), stats.nr_active_slabs, stats.nr_slabs, 100.0 * stats.nr_active_slabs / stats.nr_slabs, /* xgettext:no-c-format */ _("Active / Total Caches (% used)"), stats.nr_active_caches, stats.nr_caches, 100.0 * stats.nr_active_caches / stats.nr_caches, /* xgettext:no-c-format */ _("Active / Total Size (% used)"), stats.active_size / 1024.0, stats.total_size / 1024.0, 100.0 * stats.active_size / stats.total_size, _("Minimum / Average / Maximum Object"), stats.min_obj_size / 1024.0, stats.avg_obj_size / 1024.0, stats.max_obj_size / 1024.0); slab_list = slabsort(slab_list); attron(A_REVERSE); /* Translation Hint: Please keep alignment of the * following intact. */ print_line("%-78s/n", _(" OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME")); attroff(A_REVERSE); curr = slab_list; for (i = 0; i < rows - 8 && curr->next; i++) { print_line("%6u %6u %3u%% %7.2fK %6u %8u %9uK %-23s/n", curr->nr_objs, curr->nr_active_objs, curr->use, curr->obj_size / 1024.0, curr->nr_slabs, curr->objs_per_slab, (unsigned)(curr->cache_size / 1024), curr->name); curr = curr->next; } put_slabinfo(slab_list); if (!run_once) { refresh(); FD_ZERO(&readfds); FD_SET(STDIN_FILENO, &readfds); tv.tv_sec = delay; tv.tv_usec = 0; if (select(STDOUT_FILENO, &readfds, NULL, NULL, &tv) > 0) { if (read(STDIN_FILENO, &c, 1) != 1) break; parse_input(c); } } } while (delay); tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_tty); free_slabinfo(slab_list); if (!run_once) endwin(); return retval;}
开发者ID:gs0622,项目名称:procps,代码行数:101,
示例18: openptyintopenpty (int *amaster, int *aslave, char *name, struct termios const *termp, struct winsize const *winp){ int master; char *slave_name; int slave;# if HAVE__GETPTY /* IRIX */ slave_name = _getpty (&master, O_RDWR, 0622, 0); if (slave_name == NULL) return -1;# else /* AIX 5.1, HP-UX 11, Solaris 10, mingw */# if HAVE_POSIX_OPENPT /* Solaris 10 */ master = posix_openpt (O_RDWR | O_NOCTTY); if (master < 0) return -1;# else /* AIX 5.1, HP-UX 11, Solaris 9, mingw */# ifdef _AIX /* AIX */ master = open ("/dev/ptc", O_RDWR | O_NOCTTY); if (master < 0) return -1;# else /* HP-UX 11, Solaris 9, mingw */ /* HP-UX, Solaris have /dev/ptmx. HP-UX also has /dev/ptym/clone, but this should not be needed. Linux also has /dev/ptmx, but Linux already has openpty(). MacOS X also has /dev/ptmx, but MacOS X already has openpty(). OSF/1 also has /dev/ptmx and /dev/ptmx_bsd, but OSF/1 already has openpty(). */ master = open ("/dev/ptmx", O_RDWR | O_NOCTTY); if (master < 0) return -1;# endif# endif /* If all this does not work, we could try to open, one by one: - On MacOS X: /dev/pty[p-w][0-9a-f] - On *BSD: /dev/pty[p-sP-S][0-9a-v] - On AIX: /dev/ptyp[0-9a-f] - On HP-UX: /dev/pty[p-r][0-9a-f] - On OSF/1: /dev/pty[p-q][0-9a-f] - On Solaris: /dev/pty[p-r][0-9a-f] */# endif /* This call does not require a dependency to the 'grantpt' module, because AIX, HP-UX, IRIX, Solaris all have the grantpt() function. */ if (grantpt (master)) goto fail; /* This call does not require a dependency to the 'unlockpt' module, because AIX, HP-UX, IRIX, Solaris all have the unlockpt() function. */ if (unlockpt (master)) goto fail;# if !HAVE__GETPTY /* !IRIX */ slave_name = ptsname (master); if (slave_name == NULL) goto fail;# endif slave = open (slave_name, O_RDWR | O_NOCTTY); if (slave == -1) goto fail;# if defined __sun || defined __hpux /* Solaris, HP-UX */ if (ioctl (slave, I_PUSH, "ptem") < 0 || ioctl (slave, I_PUSH, "ldterm") < 0# if defined __sun || ioctl (slave, I_PUSH, "ttcompat") < 0# endif ) { close (slave); goto fail; }# endif /* XXX Should we ignore errors here? */ if (termp) tcsetattr (slave, TCSAFLUSH, termp); if (winp) ioctl (slave, TIOCSWINSZ, winp); *amaster = master; *aslave = slave; if (name != NULL) strcpy (name, slave_name);//.........这里部分代码省略.........
开发者ID:DanielMSchmidt,项目名称:it-sec,代码行数:101,
示例19: mainint main(int argc, char **argv){ int vfd, afd, c; int filefd; const char *videodev = "/dev/dvb/adapter0/video0"; const char *audiodev = "/dev/dvb/adapter0/audio0"; if (((tcgetpgrp(STDIN_FILENO) == getpid()) || (getppid() != (pid_t)1)) && (tcgetattr(STDIN_FILENO, &term) == 0)) { struct termios newterm; memcpy(&newterm, &term, sizeof(struct termios)); newterm.c_iflag = 0; newterm.c_lflag &= ~(ICANON | ECHO); newterm.c_cc[VMIN] = 0; newterm.c_cc[VTIME] = 0; atexit(restore); tcsetattr(STDIN_FILENO, TCSANOW, &newterm); } opterr = 0; while ((c = getopt(argc, argv, "+daA")) != -1) { switch (c) { case 'd': dolby++; break; case 'a': audio++; break; case 'A': audio++; black++; break; case '?': fprintf(stderr, "usage: test_av_play [-d] [-a] [-A] mpeg_A+V_PES_file/n"); return 1; default: break; } } argv += optind; argc -= optind; if (getenv("VIDEO")) videodev = getenv("VIDEO"); if (getenv("AUDIO")) audiodev = getenv("AUDIO"); printf("using video device '%s'/n", videodev); printf("using audio device '%s'/n", audiodev); putchar('/n'); printf("Freeze by pressing `z'/n"); printf("Stop by pressing `s'/n"); printf("Continue by pressing `c'/n"); printf("Start by pressing `p'/n"); printf("FastForward by pressing `f'/n"); printf("Mute by pressing `m'/n"); printf("UnMute by pressing `u'/n"); printf("MP2/AC3 by pressing `d'/n"); printf("SlowMotion by pressing `l'/n"); printf("Quit by pressing `q'/n"); putchar('/n'); errno = ENOENT; if (!argv[0] || (filefd = open(argv[0], O_RDONLY)) < 0) { perror("File open:"); return -1; } if ((vfd = open(videodev,O_RDWR|O_NONBLOCK)) < 0) { perror("VIDEO DEVICE: "); return -1; } if ((afd = open(audiodev,O_RDWR|O_NONBLOCK)) < 0) { perror("AUDIO DEVICE: "); return -1; } play_file_av(filefd, vfd, afd); close(vfd); close(afd); close(filefd); return 0;}
开发者ID:OpenHyperCube,项目名称:dvb-apps,代码行数:85,
示例20: BarTermRestore/* Restore terminal settings * @param Old settings */void BarTermRestore (struct termios *termOrig) { tcsetattr (fileno (stdin), TCSANOW, termOrig);}
开发者ID:PegasusEpsilon,项目名称:pianobarfly,代码行数:6,
示例21: microcom_mainint microcom_main(int argc, char **argv){ struct pollfd pfd[2];#define sfd (pfd[1].fd) char *device_lock_file = NULL; const char *s; const char *opt_s = "9600"; unsigned speed; int len; int exitcode = 1; struct termios tio0, tiosfd, tio; getopt32(argv, "s:", &opt_s); argc -= optind; argv += optind; if (!argv[0]) bb_show_usage(); speed = xatou(opt_s); // try to create lock file in /var/lock s = bb_basename(argv[0]); if (!s[0]) { errno = ENODEV; bb_perror_msg_and_die("can't lock device"); } device_lock_file = xasprintf("/var/lock/LCK..%s", s); sfd = open(device_lock_file, O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0644); if (sfd < 0) { if (ENABLE_FEATURE_CLEAN_UP) free(device_lock_file); device_lock_file = NULL; if (errno == EEXIST) bb_perror_msg_and_die("can't lock device"); // We don't abort on other errors: /var/lock can be // non-writable or non-existent } else { // %4d to make mgetty happy. It treats 4-bytes lock files as binary, // not text, PID. Making 5+ char file. Brrr... s = xasprintf("%4d/n", getpid()); write(sfd, s, strlen(s)); if (ENABLE_FEATURE_CLEAN_UP) free((char*)s); close(sfd); } // open device sfd = open(argv[0], O_RDWR); if (sfd < 0) { bb_perror_msg("can't open device"); goto unlock_and_exit; } // put stdin to "raw mode", handle one character at a time tcgetattr(STDIN_FILENO, &tio0); tio = tio0; tio.c_lflag &= ~(ICANON|ECHO); tio.c_iflag &= ~(IXON|ICRNL); tio.c_oflag &= ~(ONLCR); tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; if (tcsetattr(STDIN_FILENO, TCSANOW, &tio)) { bb_perror_msg("can't tcsetattr for %s", "stdin"); goto unlock_and_exit; } /* same thing for modem (plus: set baud rate) - TODO: make CLI option */ tcgetattr(sfd, &tiosfd); tio = tiosfd; tio.c_lflag &= ~(ICANON|ECHO); tio.c_iflag &= ~(IXON|ICRNL); tio.c_oflag &= ~(ONLCR); tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; cfsetispeed(&tio, tty_value_to_baud(speed)); cfsetospeed(&tio, tty_value_to_baud(speed)); if (tcsetattr(sfd, TCSANOW, &tio)) { bb_perror_msg("can't tcsetattr for %s", "device"); goto unlock_and_exit; } // disable SIGINT signal(SIGINT, SIG_IGN); // drain stdin tcflush(STDIN_FILENO, TCIFLUSH); printf("connected to '%s' (%d bps), exit with ctrl-X.../r/n", argv[0], speed); // main loop: check with poll(), then read/write bytes across pfd[0].fd = STDIN_FILENO; pfd[0].events = POLLIN; /*pfd[1].fd = sfd;*/ pfd[1].events = POLLIN; while (1) { int i; safe_poll(pfd, 2, -1); for (i = 0; i < 2; ++i) { if (pfd[i].revents & POLLIN) { len = read(pfd[i].fd, bb_common_bufsiz1, COMMON_BUFSIZE); if (len > 0) { if (!i && 24 == bb_common_bufsiz1[0])//.........这里部分代码省略.........
开发者ID:acassis,项目名称:emlinux-ssd1935,代码行数:101,
示例22: openint rlSerial::openDevice(const char *devicename, int speed, int block, int rtscts, int bits, int stopbits, int parity){#ifdef RLUNIX struct termios buf; if(fd != -1) return -1; fd = open(devicename, O_RDWR | O_NOCTTY | O_NDELAY); if(fd < 0) { return -1; } //signal(SIGINT, sighandler); if(tcgetattr(fd, &save_termios) < 0) { return -1; } buf = save_termios; buf.c_cflag = speed | CLOCAL | CREAD; if(rtscts == 1) buf.c_cflag |= CRTSCTS; if(bits == 7) buf.c_cflag |= CS7; else buf.c_cflag |= CS8; if(stopbits == 2) buf.c_cflag |= CSTOPB; if(parity == rlSerial::ODD) buf.c_cflag |= (PARENB | PARODD); if(parity == rlSerial::EVEN) buf.c_cflag |= PARENB; buf.c_lflag = IEXTEN; //ICANON; buf.c_oflag = OPOST; buf.c_cc[VMIN] = 1; buf.c_cc[VTIME] = 0;#ifndef PVMAC buf.c_line = 0;#endif buf.c_iflag = IGNBRK | IGNPAR | IXANY; if(tcsetattr(fd, TCSAFLUSH, &buf) < 0) { return -1; } //if(tcsetattr(fd, TCSANOW, &buf) < 0) { return -1; } ttystate = RAW; ttysavefd = fd; if(block == 1) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK); tcflush(fd,TCIOFLUSH);#endif#ifdef __VMS // Please set com parameters at DCL level struct dsc$descriptor_s dsc; int status; dsc.dsc$w_length = strlen(devicename); dsc.dsc$a_pointer = (char *) devicename; dsc.dsc$b_class = DSC$K_CLASS_S; dsc.dsc$b_dtype = DSC$K_DTYPE_T; status = SYS$ASSIGN(&dsc,&vms_channel,0,0); if(status != SS$_NORMAL) return -1;#endif#ifdef RLWIN32 DWORD ccsize; COMMCONFIG cc; int baudrate,ret; char devname[100]; if(strlen(devicename) > 80) return -1; sprintf(devname,"////.//%s",devicename); // Aenderung: allow more than 4 COM ports hdl = CreateFile( devname, // devicename, // pointer to name of the file GENERIC_READ | GENERIC_WRITE, // access (read-write) mode 0, // share mode 0, // pointer to security attributes OPEN_EXISTING, // how to create 0, // not overlapped I/O 0 // handle to file with attributes to copy ); if(hdl == INVALID_HANDLE_VALUE) { printf("CreateFile(%s) failed/n",devicename); return -1; } baudrate = CBR_9600; if(speed == B50 ) baudrate = 50; if(speed == B75 ) baudrate = 75; if(speed == B110 ) baudrate = CBR_110; if(speed == B134 ) baudrate = 134; if(speed == B150 ) baudrate = 150; if(speed == B200 ) baudrate = 200; if(speed == B300 ) baudrate = CBR_300; if(speed == B600 ) baudrate = CBR_600; if(speed == B1200 ) baudrate = CBR_1200; if(speed == B1800 ) baudrate = 1800; if(speed == B2400 ) baudrate = CBR_2400; if(speed == B4800 ) baudrate = CBR_4800; if(speed == B9600 ) baudrate = CBR_9600; if(speed == B19200 ) baudrate = CBR_19200; if(speed == B38400 ) baudrate = CBR_38400; if(speed == B57600 ) baudrate = CBR_57600; if(speed == B115200 ) baudrate = CBR_115200; if(speed == B230400 ) baudrate = 230400; if(speed == B460800 ) baudrate = 460800; if(speed == B500000 ) baudrate = 500000; if(speed == B576000 ) baudrate = 576000; if(speed == B921600 ) baudrate = 921600; if(speed == B1000000) baudrate = 1000000; if(speed == B1152000) baudrate = 1152000; if(speed == B1500000) baudrate = 1500000; if(speed == B2000000) baudrate = 2000000; if(speed == B2500000) baudrate = 2500000;//.........这里部分代码省略.........
开发者ID:376473984,项目名称:pvb,代码行数:101,
示例23: term_exitstatic void term_exit(void){ tcsetattr(0, TCSANOW, &oldtty);}
开发者ID:GamerSource,项目名称:qemu,代码行数:4,
示例24: OpenSerialPortint OpenSerialPort(){ int fileDescriptor = -1; struct termios options; // Open the serial port read/write, with no controlling terminal, and don't wait for a connection. // The O_NONBLOCK flag also causes subsequent I/O on the device to be non-blocking. // See open(2) ("man 2 open") for details. fileDescriptor = open("/dev/tty.iap", O_RDWR | O_NOCTTY | O_NONBLOCK); if (fileDescriptor == -1) { printf("Error opening serial port %s - %s(%d)./n", "/dev/tty.iap", strerror(errno), errno); goto error; } // Note that open() follows POSIX semantics: multiple open() calls to the same file will succeed // unless the TIOCEXCL ioctl is issued. This will prevent additional opens except by root-owned // processes. // See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details. if (ioctl(fileDescriptor, TIOCEXCL) == -1) { printf("Error setting TIOCEXCL on %s - %s(%d)./n", "/dev/tty.iap", strerror(errno), errno); goto error; } // Now that the device is open, clear the O_NONBLOCK flag so subsequent I/O will block. // See fcntl(2) ("man 2 fcntl") for details. if (fcntl(fileDescriptor, F_SETFL, 0) == -1) { printf("Error clearing O_NONBLOCK %s - %s(%d)./n", "/dev/tty.iap", strerror(errno), errno); goto error; } // Get the current options and save them so we can restore the default settings later. if (tcgetattr(fileDescriptor, &gOriginalTTYAttrs) == -1) { printf("Error getting tty attributes %s - %s(%d)./n", "/dev/tty.iap", strerror(errno), errno); goto error; } // The serial port attributes such as timeouts and baud rate are set by modifying the termios // structure and then calling tcsetattr() to cause the changes to take effect. Note that the // changes will not become effective without the tcsetattr() call. // See tcsetattr(4) ("man 4 tcsetattr") for details. options = gOriginalTTYAttrs; // Print the current input and output baud rates. // See tcsetattr(4) ("man 4 tcsetattr") for details. printf("Current input baud rate is %d/n", (int) cfgetispeed(&options)); printf("Current output baud rate is %d/n", (int) cfgetospeed(&options)); // Set raw input (non-canonical) mode, with reads blocking until either a single character // has been received or a one second timeout expires. // See tcsetattr(4) ("man 4 tcsetattr") and termios(4) ("man 4 termios") for details. cfmakeraw(&options); options.c_cc[VMIN] = 1; options.c_cc[VTIME] = 10; // The baud rate, word length, and handshake options can be set as follows: cfsetspeed(&options, B9600); // Set 19200 baud options.c_cflag |= (CS8); // RTS flow control of input printf("Input baud rate changed to %d/n", (int) cfgetispeed(&options)); printf("Output baud rate changed to %d/n", (int) cfgetospeed(&options)); // Cause the new options to take effect immediately. if (tcsetattr(fileDescriptor, TCSANOW, &options) == -1) { printf("Error setting tty attributes %s - %s(%d)./n", "/dev/tty.iap", strerror(errno), errno); goto error; } // Success return fileDescriptor; // Failure "/dev/tty.iap"error: if (fileDescriptor != -1) { close(fileDescriptor); } return -1;}
开发者ID:Paulxia,项目名称:SerialCommunicationFramework,代码行数:96,
示例25: callocstatic VeiFlockOfBirds *open_serial(char *name, VeDeviceInstance *i) { struct termios t; VeiFlockOfBirds *b; char *c; b = calloc(1,sizeof(VeiFlockOfBirds)); assert(b != NULL); if (c = veDeviceInstOption(i,"line")) b->line = veDupString(c); else { veError(MODULE,"serial source not specified in fob input definition"); return NULL; } if (c = veDeviceInstOption(i,"raw")) b->raw = atoi(c); if (c = veDeviceInstOption(i,"speed")) b->speed = str_to_bps(c); else b->speed = str_to_bps(DEFAULT_FOB_SPEED); if (b->speed < 0) return NULL; b->fd = open(b->line, O_RDWR|O_NOCTTY); if (b->fd < 0) { veError(MODULE, "could not open serial line %s: %s", b->line, strerror(errno)); return NULL; } /* setup serial line, terminal mumbo-jumbo */ if (tcgetattr(b->fd,&t)) { veError(MODULE, "could not get serial attributes for %s: %s", b->line, strerror(errno)); return NULL; } /* this is "non-portable" or "portability-hostile" but I can't figure out which of the many flags was mussing up data from the receiver, so we'll just trash them all. This also seems to kill the slow-startup bug */ t.c_iflag = 0; t.c_oflag = 0; t.c_cflag = 0; t.c_lflag = 0; t.c_cflag |= (CLOCAL|CREAD|CS8); t.c_cc[VMIN] = 1; t.c_cc[VTIME] = 0; cfsetispeed(&t,b->speed); cfsetospeed(&t,b->speed); /* setup flow control */ if (c = veDeviceInstOption(i, "flow")) { if (strcmp(c, "xonxoff") == 0) { t.c_iflag |= (IXON|IXOFF);#if defined(__sgi) t.c_cflag &= ~CNEW_RTSCTS;#elif defined(__sun) || defined(__linux) t.c_cflag &= ~CRTSCTS;#endif } else if (strcmp(c, "rtscts") == 0) { /* Hmm... RTS/CTS is not standard...great... */#if defined(__sgi) t.c_cflag |= CNEW_RTSCTS;#elif defined(__sun) || defined(__linux) t.c_cflag |= CRTSCTS;#else veError(MODULE, "RTS/CTS not supported on this platform"); return NULL;#endif } } else { t.c_iflag &= ~(IXON|IXOFF|IXANY);#if defined(__sgi) t.c_cflag &= ~CNEW_RTSCTS;#elif defined(__sun) || defined(__linux) t.c_cflag &= ~CRTSCTS;#endif } if (tcsetattr(b->fd,TCSAFLUSH,&t)) { veError(MODULE, "could not set serial attributes for %s: %s", b->line, strerror(errno)); return NULL; } /* try to sync things up in case it is already running */ sync_bird(b->fd); /* build NULL frame */ veFrameIdentity(&b->frame); if (c = veDeviceInstOption(i, "loc")) parseVector3(name,c,&b->frame.loc); if (c = veDeviceInstOption(i, "dir")) parseVector3(name,c,&b->frame.dir); if (c = veDeviceInstOption(i, "up"))//.........这里部分代码省略.........
开发者ID:mpconte,项目名称:vr-projects,代码行数:101,
示例26: ves_icall_System_ConsoleDriver_TtySetupMonoBooleanves_icall_System_ConsoleDriver_TtySetup (MonoString *keypad, MonoString *teardown, MonoArray **control_chars, int **size){ int dims; MONO_ARCH_SAVE_REGS; dims = terminal_get_dimensions (); if (dims == -1){ int cols = 0, rows = 0; const char *str = g_getenv ("COLUMNS"); if (str != NULL) cols = atoi (str); str = g_getenv ("LINES"); if (str != NULL) rows = atoi (str); if (cols != 0 && rows != 0) cols_and_lines = (cols << 16) | rows; else cols_and_lines = -1; } else { cols_and_lines = dims; } *size = &cols_and_lines; /* 17 is the number of entries set in set_control_chars() above. * NCCS is the total size, but, by now, we only care about those 17 values*/ mono_gc_wbarrier_generic_store (control_chars, (MonoObject*) mono_array_new (mono_domain_get (), mono_defaults.byte_class, 17)); if (tcgetattr (STDIN_FILENO, &initial_attr) == -1) return FALSE; mono_attr = initial_attr; mono_attr.c_lflag &= ~(ICANON); mono_attr.c_iflag &= ~(IXON|IXOFF); mono_attr.c_cc [VMIN] = 1; mono_attr.c_cc [VTIME] = 0;#ifdef VDSUSP /* Disable C-y being used as a suspend character on OSX */ mono_attr.c_cc [VDSUSP] = 255;#endif if (tcsetattr (STDIN_FILENO, TCSANOW, &mono_attr) == -1) return FALSE; set_control_chars (*control_chars, mono_attr.c_cc); /* If initialized from another appdomain... */ if (setup_finished) return TRUE; keypad_xmit_str = keypad != NULL ? mono_string_to_utf8 (keypad) : NULL; console_set_signal_handlers (); setup_finished = TRUE; if (!atexit_called) { if (teardown != NULL) teardown_str = mono_string_to_utf8 (teardown); atexit (tty_teardown); } return TRUE;}
开发者ID:david-lawson,项目名称:mono,代码行数:64,
示例27: mainint main(int argc, char *argv[]){ int len, cmd_finished, stop, i,try; int clientSocket, serial_fd, remotePort, status = 0; struct hostent *hostPtr = NULL; struct sockaddr_in serverName = { 0 }; unsigned char buffer[BUFFER_SIZE]; unsigned char buffer2[BUFFER_SIZE]; char *remoteHost = NULL; char *serial_device; struct termios oldtio,newtio; char *s; char *hex_filename; FILE *hexfile; if (2 != argc) { fprintf(stderr, "Usage: %s <serial_device>/n", argv[0]); exit(1); }; serial_device = argv[1]; /* Open modem device for reading and writing and not as controlling tty because we don't want to get killed if linenoise sends CTRL-C. */ serial_fd = open(serial_device, O_RDWR | O_NOCTTY ); if (serial_fd <0) {perror(serial_device); exit(-1); } tcgetattr(serial_fd,&oldtio); /* save current port settings */ bzero(&newtio, sizeof(newtio)); /* BAUDRATE: Set bps rate. You could also use cfsetispeed and cfsetospeed. CRTSCTS : output hardware flow control (only used if the cable has all necessary lines. See sect. 7 of Serial-HOWTO) CS8 : 8n1 (8bit,no parity,1 stopbit) CLOCAL : local connection, no modem contol CREAD : enable receiving characters */ newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD; /* IGNPAR : ignore bytes with parity errors ICRNL : map CR to NL (otherwise a CR input on the other computer will not terminate input) otherwise make device raw (no other input processing) */ newtio.c_iflag = IGNPAR; /* Raw output. */ newtio.c_oflag = 0; /* set input mode (non-canonical, no echo,...) disable all echo functionality, and don't send signals to calling program */ newtio.c_lflag = 0; newtio.c_cc[VTIME] = 50; /* time out after 5 seconds */ newtio.c_cc[VMIN] = 0; /* non-blocking read */ /* now clean the modem line and activate the settings for the port */ tcflush(serial_fd, TCIFLUSH); tcsetattr(serial_fd,TCSANOW,&newtio); printf("Sending break/n"); /* Send a break to reset device into ISP mode */ tcsendbreak(serial_fd,3); tcflush(serial_fd, TCIFLUSH); usleep(1000000); tcflush(serial_fd, TCIFLUSH); usleep(1000000); /* Send an uppercase U to negotiate baud rate */ buffer[0] = 'U'; buffer[1] = 0; /* Send U to serial line */ if (write_all(serial_fd, buffer, 1) == -1) { perror("sendall"); printf("We only sent %d bytes because of the error!/n", len); }; len = read_cmd(serial_fd, buffer); buffer[len] = 0; printf("Read %d characters:/n/t", len, buffer[0]); for (i=0; i<len; i++) printf("%02x ", buffer[i]); printf("/n"); //.........这里部分代码省略.........
开发者ID:elmo2k3,项目名称:McBetty,代码行数:101,
示例28: shell_builtin_read//.........这里部分代码省略......... fd = bb_strtou(opt_u, NULL, 10); if (fd < 0 || errno) return "invalid file descriptor"; } if (opt_p && isatty(fd)) { fputs(opt_p, stderr); fflush_all(); } if (ifs == NULL) ifs = defifs; if (nchars || (read_flags & BUILTIN_READ_SILENT)) { tcgetattr(fd, &tty); old_tty = tty; if (nchars) { tty.c_lflag &= ~ICANON; // Setting it to more than 1 breaks poll(): // it blocks even if there's data. !?? //tty.c_cc[VMIN] = nchars < 256 ? nchars : 255; /* reads would block only if < 1 char is available */ tty.c_cc[VMIN] = 1; /* no timeout (reads block forever) */ tty.c_cc[VTIME] = 0; } if (read_flags & BUILTIN_READ_SILENT) { tty.c_lflag &= ~(ECHO | ECHOK | ECHONL); } /* This forces execution of "restoring" tcgetattr later */ read_flags |= BUILTIN_READ_SILENT; /* if tcgetattr failed, tcsetattr will fail too. * Ignoring, it's harmless. */ tcsetattr(fd, TCSANOW, &tty); } retval = (const char *)(uintptr_t)0; startword = 1; backslash = 0; if (end_ms) /* NB: end_ms stays nonzero: */ end_ms = ((unsigned)monotonic_ms() + end_ms) | 1; buffer = NULL; bufpos = 0; do { char c; struct pollfd pfd[1]; int timeout; if ((bufpos & 0xff) == 0) buffer = xrealloc(buffer, bufpos + 0x101); timeout = -1; if (end_ms) { timeout = end_ms - (unsigned)monotonic_ms(); if (timeout <= 0) { /* already late? */ retval = (const char *)(uintptr_t)1; goto ret; } } /* We must poll even if timeout is -1: * we want to be interrupted if signal arrives, * regardless of SA_RESTART-ness of that signal! */ errno = 0; pfd[0].fd = fd;
开发者ID:Antares84,项目名称:asuswrt-merlin,代码行数:67,
注:本文中的tcsetattr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ tcsetpgrp函数代码示例 C++ tcsendbreak函数代码示例 |