这篇教程C++ tcdrain函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中tcdrain函数的典型用法代码示例。如果您正苦于以下问题:C++ tcdrain函数的具体用法?C++ tcdrain怎么用?C++ tcdrain使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了tcdrain函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: gpsd_writessize_t gpsd_write(struct gps_device_t * session, const char *buf, size_t len){ ssize_t status; bool ok; if (session == NULL || session->context == NULL || session->context->readonly) return 0; status = write(session->gpsdata.gps_fd, buf, len); ok = (status == (ssize_t) len); (void)tcdrain(session->gpsdata.gps_fd); /* extra guard prevents expensive hexdump calls */ if (session->context->debug >= LOG_IO) gpsd_report(LOG_IO, "=> GPS: %s%s/n", gpsd_packetdump((char *)buf, len), ok ? "" : " FAILED"); return status;}
开发者ID:vyacht,项目名称:carambola,代码行数:16,
示例2: serialport_flushvoid serialport_flush(void){ static unsigned char b; unsigned int t; if(serial_port) { t = serialport_get_character_timeout_0_1s(); serialport_set_character_timeout_0_1s(0); tcdrain(serial_port); while(read(serial_port, &b, 1) > 0); serialport_set_character_timeout_0_1s(t); }}
开发者ID:murix,项目名称:esptool-ck,代码行数:16,
示例3: gecko_writeint gecko_write(const void *buf, size_t count) { size_t left, chunk;#ifndef __WIN32__ size_t res;#else DWORD res;#endif left = count; while (left) { chunk = left; if (chunk > FTDI_PACKET_SIZE) chunk = FTDI_PACKET_SIZE;#ifdef USE_LIBFTDI if (gUsingFTDI) res = ftdi_write_data(&gFTDIContext, (unsigned char *)buf, chunk); else#endif #ifndef __WIN32__ res = write(fd_gecko, buf, count); if (res < 1) { perror("gecko_write"); return 1; }#else if (!WriteFile(handle_gecko, buf, chunk, &res, NULL)) { fprintf (stderr, "gecko_write/n"); return 1; }#endif left -= res; buf += res;#if !defined(__WIN32__) && !defined(USE_LIBFTDI) // does this work with ftdi-sio? if (tcdrain(fd_gecko)) { perror ("gecko_drain"); return 1; }#endif } return 0;}
开发者ID:devkitPro,项目名称:wiiload,代码行数:47,
示例4: WaitCommEventvoid RS232Interface::WaitForTxEmpty(){#ifdef _WINDOWS DWORD evento; if ( hCom != INVALID_HANDLE_VALUE) { do { WaitCommEvent(hCom, &evento, NULL); } while ( !(evento & EV_TXEMPTY) ); }#endif#ifdef _LINUX_ if ( fd != INVALID_HANDLE_VALUE ) tcdrain(fd);#endif}
开发者ID:bieli,项目名称:avr_jokes,代码行数:17,
示例5: gpsd_closevoid gpsd_close(struct gps_device_t *session){ if (session->gpsdata.gps_fd != -1) { (void)ioctl(session->gpsdata.gps_fd, (unsigned long)TIOCNXCL); (void)tcdrain(session->gpsdata.gps_fd); if (isatty(session->gpsdata.gps_fd) != 0) { /* force hangup on close on systems that don't do HUPCL properly */ /*@ ignore @*/ (void)cfsetispeed(&session->ttyset, (speed_t) B0); (void)cfsetospeed(&session->ttyset, (speed_t) B0); /*@ end @*/ (void)tcsetattr(session->gpsdata.gps_fd, TCSANOW, &session->ttyset); } /* this is the clean way to do it */ session->ttyset_old.c_cflag |= HUPCL; /* keep the most recent baud rate */ /* * Don't revert the serial parameters if we didn't have to mess with * them the first time. Economical, and avoids tripping over an * obscure Linux 2.6 kernel bug that disables threaded * ioctl(TIOCMWAIT) on a device after tcsetattr() is called. * * Unfortunately the termios struct doesn't have c_ispeed/c_ospeed * on all architectures. Its missing on sparc, mips/mispel and hurd-i386 at least. */#if defined(_HAVE_STRUCT_TERMIOS_C_ISPEED) if (session->ttyset_old.c_ispeed != session->ttyset.c_ispeed || (session->ttyset_old.c_cflag & CSTOPB) != (session->ttyset.c_cflag & CSTOPB)) {#endif /*@ ignore @*/ (void)cfsetispeed(&session->ttyset_old, (speed_t) session->gpsdata.dev.baudrate); (void)cfsetospeed(&session->ttyset_old, (speed_t) session->gpsdata.dev.baudrate); /*@ end @*/ (void)tcsetattr(session->gpsdata.gps_fd, TCSANOW, &session->ttyset_old);#if defined(_HAVE_STRUCT_TERMIOS_C_ISPEED) }#endif gpsd_report(LOG_SPIN, "close(%d) in gpsd_close(%s)/n", session->gpsdata.gps_fd, session->gpsdata.dev.path); (void)close(session->gpsdata.gps_fd); session->gpsdata.gps_fd = -1; }}
开发者ID:jcable,项目名称:gpsd,代码行数:46,
示例6: _write_port// ------------------------------------------------------------------------------// Write Port with Lock// ------------------------------------------------------------------------------void _write_port(char *buf, unsigned len){ // Lock pthread_mutex_lock(&lock); // Write packet via serial link write(fd, buf, len); // Wait until all data has been written tcdrain(fd); // Unlock pthread_mutex_unlock(&lock); return;}
开发者ID:Yunaik,项目名称:asp,代码行数:20,
示例7: write/** * @brief Update all information by bust read * @retval 0 Success * @retval -1 Failed * * - See burst read function at pp.14 * - Data resolution is 16 bit */int Adis16470::update_burst(void){ unsigned char buff[64] = {0}; // 0x6800: Burst read function buff[0] = 0x61; buff[1] = 0x68; buff[2] = 0x00; int size = write(fd_, buff, 24); if (size != 24) { perror("update_burst"); return -1; } if (tcdrain(fd_) < 0) { perror("update_burst"); return -1; } size = read(fd_, buff, 30); if (size != 30) { perror("update_burst"); return -1; } int16_t diag_stat = big_endian_to_short(&buff[3]); if (diag_stat != 0) { fprintf(stderr, "diag_stat error: %04x/n", (uint16_t)diag_stat); return -1; } // X_GYRO_OUT gyro[0] = big_endian_to_short(&buff[5]) * M_PI / 180 / 10.0; // Y_GYRO_OUT gyro[1] = big_endian_to_short(&buff[7]) * M_PI / 180 / 10.0; // Z_GYRO_OUT gyro[2] = big_endian_to_short(&buff[9]) * M_PI / 180 / 10.0; // X_ACCL_OUT accl[0] = big_endian_to_short(&buff[11]) * M_PI / 180 / 10.0; // Y_ACCL_OUT accl[1] = big_endian_to_short(&buff[13]) * M_PI / 180 / 10.0; // Z_ACCL_OUT accl[2] = big_endian_to_short(&buff[15]) * M_PI / 180 / 10.0; return 0;}
开发者ID:hatem-darweesh,项目名称:Autoware,代码行数:53,
示例8: write_drainint write_drain( int fd, const unsigned char *data, unsigned long length ){ int i, result, block; if ( length == 0 ) { return; } tcflush( fd, TCIFLUSH ); for ( result = 1, i = 0 ; result > 0 && i < length ; ) { if ( (length - i) > progress_block ) { block = progress_block; } else { block = length - i; } result = write( fd, data + i, block ); tcdrain( fd ); if ( result >= 0 ) { i += result; } else { perror( "Error writing to port/n" ); } if ( progress ) { printf( "." ); fflush( stdout ); } } if (dump_comms) { if ( progress ) { printf( "/n" ); } printf( "Sent:/n" ); dump( data, length ); }}
开发者ID:wodz,项目名称:open21xx,代码行数:45,
示例9: _srmio_ios_writestatic int _srmio_ios_write( srmio_io_t h, const unsigned char *buf, size_t len, srmio_error_t *err ){ int ret; assert( h ); assert( buf ); ret = write( SELF(h)->fd, buf, len ); if( ret < 0 ){ srmio_error_errno( err, "ios write" ); } else { tcdrain( SELF(h)->fd ); } return ret;}
开发者ID:crashracer,项目名称:srmio,代码行数:18,
示例10: cached_sttystatic int cached_stty(int fd,Sgttyb *buf){ int xfd = (0 <= fd && fd < MAXFD) ? fd: MAXFD-1; int rcode; if( cur_sgttyb[xfd].SG_flags != buf->SG_flags || cur_sgttyb[xfd].SG_lflag != buf->SG_lflag ){ cur_sgttyb[xfd] = *buf;#ifdef hpux tcdrain(fd); usleep(100*1000);#endif rcode = TCsetattr(fd,buf);#ifdef hpux set_cbreak(fd,!(buf->SG_lflag&ICANON));#endif return rcode; }else return 0;}
开发者ID:2dot4,项目名称:Psiphon3-for-Linux,代码行数:18,
示例11: errorvoid SerialConnection::sendCommand(QByteArray cmd) {#ifdef _WIN32 DWORD bytes_sent;#endif mode = MODE_NORMAL; if (context != NULL) {#ifdef _WIN32 if (!WriteFile(*((HANDLE*)context), cmd.constData(), cmd.length(), &bytes_sent, 0) || bytes_sent != (DWORD)cmd.length()) emit error(QString("unable to send command."));#else if (write(*((int*)context), cmd.constData(), cmd.length()) != cmd.length()) emit error(QString("unable to send command")); tcdrain(*((int*)context));#endif } else { emit error("cannot send command if disconnected from usb device."); }}
开发者ID:mickael9,项目名称:kilobots-toolchain,代码行数:18,
示例12: serial_writeint serial_write(struct serial_dev * dev, const void * buf, unsigned int len){ int fd; int n; assert(dev != NULL); fd = dev->fd; if ((n = write(fd, buf, len)) < 0) { perror("write():"); return n; } tcdrain(fd); return n;}
开发者ID:k0059,项目名称:yard-ice,代码行数:19,
示例13: vrpn_drain_output_buffer// empty the output buffer, waiting for all of the chars to be delivered// Return 0 on success, nonzero on failure.// NOT CALLED! OBSOLETE? -- no ... used by vrpn_Flockint vrpn_drain_output_buffer(int comm){#ifdef VERBOSE printf("vrpn_drain_output_buffer(): Entering/n");#endif#if defined(hpux) || defined(__hpux) || defined(ultrix) || defined(__CYGWIN__) fprintf(stderr, "vrpn_drain_output_buffer: Not impemented on NT, ultrix, or HP/n"); return -1;#else#if defined(_WIN32) return FlushFileBuffers(commConnections[comm]) == 0;#else return tcdrain(comm);#endif#endif}
开发者ID:Lab411-HUST,项目名称:Github,代码行数:22,
示例14: serial_closeint serial_close(int filedescriptor){ if(tcdrain(filedescriptor) < 0){ perror("serial_close: tcdrain"); return -1; } if(tcflush(filedescriptor, TCIOFLUSH) < 0){ perror("serial_close: tcflush"); return -2; } if(close(filedescriptor) < 0){ perror("serial_close: close"); return -3; } return 0;}
开发者ID:poftwaresatent,项目名称:crbsick,代码行数:19,
示例15: rpi_comport_setbaudint rpi_comport_setbaud(int baudrate){ struct termios tmptio; if (fd_comport <= 0) { fprintf(stderr, "Error in coding: RPi comport wasn't opened./n"); exit(-1); } /* get current port settings */ tcgetattr(fd_comport, &tmptio); /* set new baud rate and preserve everything else */ cfsetspeed(&tmptio, baudrate); tcdrain(fd_comport); tcflush(fd_comport, TCIOFLUSH); //msleep(500); tcsetattr(fd_comport, TCSANOW, &tmptio); msleep(500); return 0;}
开发者ID:BackupGGCode,项目名称:raspy-juice,代码行数:19,
示例16: ao_gps_openintao_gps_open(const char *tty){ struct termios termios; int fd; fd = open (tty, O_RDWR); if (fd < 0) return -1; tcgetattr(fd, &termios); cfmakeraw(&termios); cfsetspeed(&termios, B4800); tcsetattr(fd, TCSAFLUSH, &termios); tcdrain(fd); tcflush(fd, TCIFLUSH); return fd;}
开发者ID:tarcteams,项目名称:Telemini-and-AltOS,代码行数:19,
示例17: scope_write/* * Write command string to scope with delays. */static void scope_write(int fd, unsigned int *cmd){ int i; unsigned char c; for (i = 1; i <= cmd[0]; i++) { if (cmd[i] >= 0x100) { tcdrain(fd); usleep((cmd[i] - 0x100) * 1000); } else { c = cmd[i]; write(fd, &c, 1); } }}
开发者ID:shoupydad,项目名称:CCDAuto,代码行数:22,
示例18: Close//// CloseSerialPort()//// Close the serial port.// We close the serial port when switching ports or quitting.//void TMSerialPort::Close() { if (fd != kSerialError) { // Block until all written output has been sent from the device. // Note that this call is simply passed on to the serial device driver. // See tcsendbreak(3) ("man 3 tcsendbreak") for details. if (tcdrain(fd) == kSerialError && output != NULL) fprintf(output, "Error waiting for drain - %s(%d)./n", strerror(errno), errno); // It is good practice to reset a serial port back to the state in // which you found it. This is why we saved the original termios struct // The constant TCSANOW (defined in termios.h) indicates that // the change should take effect immediately. if (tcsetattr(fd, TCSANOW, &originalAttribs) == kSerialError && output != NULL) fprintf(output, "Error resetting tty attributes - %s(%d)./n", strerror(errno), errno); close(fd); fd = kSerialError; }}
开发者ID:Hyldahl,项目名称:TabletMagic,代码行数:25,
示例19: LockATMO_BOOL CAtmoClassicConnection::SendData(pColorPacket data) { if(m_hComport == INVALID_HANDLE_VALUE) return ATMO_FALSE; unsigned char buffer[19]; DWORD iBytesWritten; buffer[0] = 0xFF; // Start Byte buffer[1] = 0x00; // Start channel 0 buffer[2] = 0x00; // Start channel 0 buffer[3] = 15; // int iBuffer = 4; int idx; Lock(); for(int i=0; i < 5 ; i++) { if(m_ChannelAssignment && (i < m_NumAssignedChannels)) idx = m_ChannelAssignment[i]; else idx = -1; if((idx>=0) && (idx<data->numColors)) { buffer[iBuffer++] = data->zone[idx].r; buffer[iBuffer++] = data->zone[idx].g; buffer[iBuffer++] = data->zone[idx].b; } else { buffer[iBuffer++] = 0; buffer[iBuffer++] = 0; buffer[iBuffer++] = 0; } }#if defined(WIN32) WriteFile(m_hComport, buffer, 19, &iBytesWritten, NULL); // send to COM-Port#else iBytesWritten = write(m_hComport, buffer, 19); tcdrain(m_hComport);#endif Unlock(); return (iBytesWritten == 19) ? ATMO_TRUE : ATMO_FALSE;}
开发者ID:CSRedRat,项目名称:vlc,代码行数:43,
示例20: gpsd_closevoid gpsd_close(struct gps_device_t *session){ if (!BAD_SOCKET(session->gpsdata.gps_fd)) { (void)ioctl(session->gpsdata.gps_fd, (unsigned long)TIOCNXCL); (void)tcdrain(session->gpsdata.gps_fd); if (isatty(session->gpsdata.gps_fd) != 0) { /* force hangup on close on systems that don't do HUPCL properly */ /*@ ignore @*/ (void)cfsetispeed(&session->ttyset, (speed_t) B0); (void)cfsetospeed(&session->ttyset, (speed_t) B0); /*@ end @*/ (void)tcsetattr(session->gpsdata.gps_fd, TCSANOW, &session->ttyset); } /* this is the clean way to do it */ session->ttyset_old.c_cflag |= HUPCL; /* * Don't revert the serial parameters if we didn't have to mess with * them the first time. Economical, and avoids tripping over an * obscure Linux 2.6 kernel bug that disables threaded * ioctl(TIOCMWAIT) on a device after tcsetattr() is called. */ if (cfgetispeed(&session->ttyset_old) != cfgetispeed(&session->ttyset) || (session->ttyset_old.c_cflag & CSTOPB) != (session->ttyset.c_cflag & CSTOPB)) { /* * If we revert, keep the most recent baud rate. * Cuts down on autobaud overhead the next time. */ /*@ ignore @*/ (void)cfsetispeed(&session->ttyset_old, (speed_t) session->gpsdata.dev.baudrate); (void)cfsetospeed(&session->ttyset_old, (speed_t) session->gpsdata.dev.baudrate); /*@ end @*/ (void)tcsetattr(session->gpsdata.gps_fd, TCSANOW, &session->ttyset_old); } gpsd_report(session->context->debug, LOG_SPIN, "close(%d) in gpsd_close(%s)/n", session->gpsdata.gps_fd, session->gpsdata.dev.path); (void)close(session->gpsdata.gps_fd); session->gpsdata.gps_fd = -1; }}
开发者ID:vyacht,项目名称:gpsd,代码行数:43,
示例21: write_rs485/* send through rs485 * return: bytes send */int write_rs485 (int fd, const char *data, const int nr){ int size = 0; int state; if (nr == 0 || fd < 0) return 0; usleep(RS485_DELAY_BEFORE * 1000); /* send */ size = write(fd, data, nr); /* wait for all data send */ tcdrain(fd); usleep(RS485_DELAY_AFTER * 1000); return size;}
开发者ID:gucong,项目名称:robotxq,代码行数:22,
示例22: LockATMO_BOOL CAtmoDmxSerialConnection::SendData(pColorPacket data) { if(m_hComport == INVALID_HANDLE_VALUE) return ATMO_FALSE; int iBuffer = 2; DWORD iBytesWritten; Lock(); int idx, z = 0; for(int i=0;i<getNumChannels();i++) { if(m_ChannelAssignment && (i < m_NumAssignedChannels)) idx = m_ChannelAssignment[i]; else idx = -1; if((idx>=0) && (idx<data->numColors)) { if( m_dmx_channels_base[z] >= 0 ) iBuffer = m_dmx_channels_base[z] + 2; else iBuffer += 3; DMXout[iBuffer] = data->zone[ idx ].r; DMXout[iBuffer+1] = data->zone[ idx ].g; DMXout[iBuffer+2] = data->zone[ idx ].b; } if( m_dmx_channels_base[z] >= 0 ) z++; }#if defined(WIN32) WriteFile(m_hComport, DMXout, 259, &iBytesWritten, NULL); // send to COM-Port#else iBytesWritten = write(m_hComport, DMXout, 259); tcdrain(m_hComport);#endif Unlock(); return (iBytesWritten == 259) ? ATMO_TRUE : ATMO_FALSE;}
开发者ID:iamnpc,项目名称:myfaplayer,代码行数:42,
示例23: oceanserver_sendstatic int oceanserver_send(int fd, const char *fmt, ...){ int status; char buf[BUFSIZ]; va_list ap; va_start(ap, fmt); (void)vsnprintf(buf, sizeof(buf) - 5, fmt, ap); va_end(ap); (void)strlcat(buf, "", BUFSIZ); status = (int)write(fd, buf, strlen(buf)); (void)tcdrain(fd); if (status == (int)strlen(buf)) { gpsd_report(LOG_IO, "=> GPS: %s/n", buf); return status; } else { gpsd_report(LOG_WARN, "=> GPS: %s FAILED/n", buf); return -1; }}
开发者ID:biiont,项目名称:gpsd,代码行数:20,
示例24: mraa_uart_flushmraa_result_tmraa_uart_flush(mraa_uart_context dev){ if (!dev) { syslog(LOG_ERR, "uart: flush: context is NULL"); return MRAA_ERROR_INVALID_HANDLE; } if (IS_FUNC_DEFINED(dev, uart_flush_replace)) { return dev->advance_func->uart_flush_replace(dev); }#if !defined(PERIPHERALMAN) if (tcdrain(dev->fd) == -1) { return MRAA_ERROR_FEATURE_NOT_SUPPORTED; }#endif return MRAA_SUCCESS;}
开发者ID:jontrulson,项目名称:mraa,代码行数:20,
示例25: closeSerialPort// Given the file descriptor for a serial device, close that device.void closeSerialPort(int fileDescriptor){ // Block until all written output has been sent from the device. // Note that this call is simply passed on to the serial device driver. // See tcsendbreak(3) <x-man-page://3/tcsendbreak> for details. if (tcdrain(fileDescriptor) == -1) { printf("Error waiting for drain - %s(%d)./n", strerror(errno), errno); } // Traditionally it is good practice to reset a serial port back to // the state in which you found it. This is why the original termios struct // was saved. if (tcsetattr(fileDescriptor, TCSANOW, &gOriginalTTYAttrs) == -1) { printf("Error resetting tty attributes - %s(%d)./n", strerror(errno), errno); } close(fileDescriptor);}
开发者ID:rockus,项目名称:VE.direct-OSX-Linux,代码行数:21,
示例26: mmWriteint mmWrite(struct ModemStream* modem, char *buffer, int bytes){ #ifdef ARDUINO return modem->stream->write(buffer, bytes); #endif #ifdef LINUX int written = write(modem->fd, buffer, bytes); tcdrain(modem->fd); return written; #endif #ifdef _WIN32 DWORD bytesSend; if (!WriteFile(modem->hSerial, buffer, bytes, &bytesSend, 0)) { ClearCommError(modem->hSerial, modem->errors, &modem->status); return -1; } else return (int)bytesSend; #endif}
开发者ID:M2MCircuits,项目名称:makermodem,代码行数:20,
示例27: close_serialvoid close_serial(){ int p; int ports = 1; const char close_code[2] = "9"; if (on_serial == 0) return; if (on_serial == 3) ports = 2; printf("sending termination code to serial port(s)./n"); for (p=0; p<ports; p++){ write(serial_fd[p], close_code, 1); if(!use_tcp){ tcdrain(serial_fd[p]); tcsetattr(serial_fd[p], TCSANOW, &oldtio[p]); } close(serial_fd[p]); }}
开发者ID:nilimsarma,项目名称:Blokus_FPGA,代码行数:20,
示例28: slow_writeint slow_write(int fd,char *d,int l,int preWait){ // UART is at 2Mbps, but we need to allow enough time for a whole line of // writing. 100 chars x 0.5usec = 500usec. So 1ms between chars should be ok. // printf("Writing [%s]/n",d); int i; usleep(preWait); for(i=0;i<l;i++) { int w=write(fd,&d[i],1); while (w<1) { usleep(1000); w=write(fd,&d[i],1); } // Only control characters can cause us whole line delays, if (d[i]<' ') { usleep(2000); } else usleep(0); } tcdrain(fd); return 0;}
开发者ID:MEGA65,项目名称:mega65-core,代码行数:20,
注:本文中的tcdrain函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ tcf_csum_skb_nextlayer函数代码示例 C++ tcase_set_timeout函数代码示例 |