当前位置: 首页>>代码示例>>C++>>正文


C++ ClearCommError函数代码示例

本文整理汇总了C++中ClearCommError函数的典型用法代码示例。如果您正苦于以下问题:C++ ClearCommError函数的具体用法?C++ ClearCommError怎么用?C++ ClearCommError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ClearCommError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ClearCommError

int CSerial::ReadDataWaiting( void )
{

	if( !m_bOpened || m_hIDComDev == NULL ) return( 0 );

	DWORD dwErrorFlags;
	COMSTAT ComStat;

	ClearCommError( m_hIDComDev, &dwErrorFlags, &ComStat );

	return( (int) ComStat.cbInQue );
}
开发者ID:herreros,项目名称:baseCam,代码行数:12,代码来源:Serial.cpp

示例2: serial_read

/*----------------------------------------------------------------------------*/
int serial_read(int fd, void *buffer, unsigned size, unsigned timeout)
{
  HANDLE h;
  COMMTIMEOUTS ct;
  int received = 0;

  h = get_h(fd);
  if(!h)
    return 0;

  if(!GetCommTimeouts(h,&ct))
  {
    err_trace(__FILE__, __LINE__);
    return 0;
  }

  ct.ReadIntervalTimeout = MAXDWORD;
  ct.ReadTotalTimeoutMultiplier = MAXDWORD;
  ct.ReadTotalTimeoutConstant = timeout;

  if(!SetCommTimeouts(h,&ct))
  {
    err_trace(__FILE__, __LINE__);
    return 0;
  }

  if(!ReadFile(h, buffer, size, (DWORD *)&received, NULL))
  {
    DWORD Err;
    err_trace(__FILE__, __LINE__);
    ClearCommBreak(h);
    ClearCommError(h, &Err, NULL);
    return 0;
  }

#ifdef DEBUG
  if(!received)
  {
//    err_trace(__FILE__, __LINE__);
//    TRACE("%s:%d: Timeout reached. Timeout: %u\n", __FILE__, __LINE__, timeout );
  }
	else
	{
		int i;
		fprintf(stderr, "rx: ");
		for(i = 0; i < received; i++)
			fprintf(stderr, "%02x ", (unsigned)((char *)buffer)[i] & 0xff);
		fprintf(stderr, "\n");
	}
#endif

  return received;
}
开发者ID:olegyurchenko,项目名称:dda-control,代码行数:54,代码来源:pc_serial.c

示例3: locker

qint64 VirtualSerialDevice::bytesAvailable() const
{
    QMutexLocker locker(&lock);
    if (!isOpen()) return 0;

    qint64 avail = 0;
    COMSTAT Status;
    if (ClearCommError(d->portHandle, NULL, &Status)) {
        avail = Status.cbInQue;
    }
    return avail + QIODevice::bytesAvailable();
}
开发者ID:KDE,项目名称:android-qt-creator,代码行数:12,代码来源:virtualserialdevice_win.cpp

示例4: ClearCommError

int	MySerial::Read(void *buffer,int len)
{
	BOOL bReadStat;
	DWORD r_len = 0;
	
	ClearCommError(hCom,&dwErrorFlags,&ComStat);

	while( ComStat.cbInQue == 0 )
	{
		ClearCommError(hCom,&dwErrorFlags,&ComStat);
	}

	bReadStat = ReadFile(hCom,buffer,len,&r_len,NULL);

	PurgeComm(hCom, PURGE_TXCLEAR|PURGE_RXCLEAR|PURGE_TXABORT|PURGE_RXABORT);

	if(!bReadStat)
		return -1;

	return r_len;
}
开发者ID:jameshilliard,项目名称:Uart_and_Tcp_Test,代码行数:21,代码来源:MySerial.cpp

示例5: bytesAvailable

qint64 QSerial::bytesAvailable() {
	if (isOpen()) {
		DWORD Errors;
		COMSTAT Status;
		bool success=ClearCommError(fh, &Errors, &Status);
		if (success) {
			return Status.cbInQue + QIODevice::bytesAvailable();
		}
		return (unsigned int)-1;
	}
	return 0;
}
开发者ID:krooks,项目名称:qsilib,代码行数:12,代码来源:qserial.cpp

示例6: TestForBreak

bool TestForBreak( void )
{
    DWORD       errors;
    COMSTAT     comStat;

    if( ClearCommError( hSerial, &errors, &comStat ) ) {
        if( errors & CE_BREAK ) {
            return TRUE;
        }
    }
    return( FALSE );
}
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:12,代码来源:sernt.c

示例7: fb_SerialGetRemaining

int fb_SerialGetRemaining( FB_FILE *handle,
                           void *pvHandle, fb_off_t *pLength )
{
    W32_SERIAL_INFO *pInfo = (W32_SERIAL_INFO*) pvHandle;
    DWORD dwErrors;
    COMSTAT Status;
    if( !ClearCommError( pInfo->hDevice, &dwErrors, &Status ) )
        return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL );
    if( pLength )
        *pLength = (long) Status.cbInQue;
    return fb_ErrorSetNum( FB_RTERROR_OK );
}
开发者ID:KurtWoloch,项目名称:fbc,代码行数:12,代码来源:io_serial.c

示例8: switch

int wxSerialPort::Ioctl(int cmd,void* args)
{
    COMSTAT comstat;
    DWORD errors;
    int result = 0;
    bool brk;
    switch(cmd) {
    case CTB_RESET:
	   return SendBreak(0);
    case CTB_SER_GETEINFO:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  // actualize the last events
		  if(errors & CE_BREAK) einfo.brk++;
		  if(errors & CE_FRAME) einfo.frame++;
		  if(errors & CE_OVERRUN) einfo.overrun++;
		  if(errors & CE_RXPARITY) einfo.parity++;
		  *(wxSerialPort_EINFO*)args = einfo;
		  return 0;
	   }
    case CTB_SER_GETBRK:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  if(errors & CE_BREAK) result = 1;
		  einfo.brk += result;
		  *(int*)args = result;
		  return 0;
	   }
	   break;
    case CTB_SER_GETFRM:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  if(errors & CE_FRAME) result = 1;
		  einfo.frame += result;
		  *(int*)args = result;
		  return 0;
	   }
    case CTB_SER_GETOVR:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  if(errors & CE_OVERRUN) result = 1;
		  einfo.overrun += result;
		  *(int*)args = result;
		  return 0;
	   }
	   break;
    case CTB_SER_GETPAR:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  if(errors & CE_RXPARITY) result = 1;
		  einfo.parity += result;
		  *(int*)args = result;
		  return 0;
	   }
	   break;
    case CTB_SER_GETINQUE:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  *(int*)args = (int)comstat.cbInQue;
		  return 0;
	   }
	   break;
    }
    // error or unknown command
    return -1;
};
开发者ID:JONA-GA,项目名称:connector_pi,代码行数:60,代码来源:serport.cpp

示例9: Send

int Send(const char * cmd)
	{
	LOG(ARDUINO_MSG_VERBOSE,"Arduino::SendMsg - msg [%s]",cmd);
	write_lock.Lock();

	DWORD dwwritten = 0; 
	int len = strlen(cmd);

	char buf[256];
	if(len>256)
	{
		write_lock.Unlock();
		LOG(ERR,"Arduino::Send: Msg too long!");
		return -1;
	}

#ifndef USBCAN_PROTOCOL
	// surround message with {}
	sprintf_s(buf,256,"{%s}\r",cmd);
	len += 3;	// {}\r
#else
	sprintf_s(buf,256,"%s\r",cmd);
	len += 1;	// \r
#endif

	if  ( (dwwritten=blockingWrite(buf, len )) == -1)
		{
		LOG(ERR,"Arduino::SendMsg - Blocking write failed ! \n");
		write_lock.Unlock();
		return -1;
		}

	if (dwwritten != len)
		{
		write_lock.Unlock();
		LOG(ERR,"Arduino::SendMsg - Write didn't finish (%d out of %d bytes sent)\n", dwwritten,len);
		DWORD   dwErrors;
		COMSTAT comStat;
		ClearCommError(hCommPort, &dwErrors, &comStat);
		LOG(ERR,"Arduino::SendMsg - ClearCommError: Error flags: 0x%x, bytes in output queue: %d\n", dwErrors, comStat.cbOutQue);		
		return -1;
		}
	write_lock.Unlock();

#ifndef USBCAN_PROTOCOL
	LOG(ARDUINO_MSG_VERBOSE,"Arduino::SendMsg - completed succefully: %d written (%d bytes original)",dwwritten,dwwritten-3);
	return dwwritten-3;
#else
	LOG(ARDUINO_MSG_VERBOSE,"Arduino::SendMsg - completed succefully: %d written (%d bytes original)",dwwritten,dwwritten-1);
	return dwwritten-1;
#endif
}
开发者ID:miaozhendaoren,项目名称:SardineCAN-Win32,代码行数:52,代码来源:Arduino.cpp

示例10: SerialPortWrite

int SerialPortWrite(char *szBuffer, int count)
{
	// TODO: Add your control notification handler code here
#if 0
	DWORD wCount = 0;
	WriteFile(hCom, szBuffer, count, &wCount, NULL);//发送数据
	return (int)wCount;
#else
	//char buffer[1024];
	//DWORD dwBytesWritten = 1024;
	DWORD dwErrorFlags;
	COMSTAT ComStat;
	OVERLAPPED m_osWrite;
	BOOL bWriteStat;
	DWORD dwRealSend = 0;

	strcat(szBuffer, "\r\n");
	count = count + 2;
	
	ZeroMemory(&m_osWrite, sizeof(m_osWrite));
	if (m_osWrite.hEvent != NULL)
	{
		ResetEvent(m_osWrite.hEvent);
		m_osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	}
	if (ClearCommError(hCom, &dwErrorFlags, NULL))
	{
		PurgeComm(hCom, PURGE_TXABORT | PURGE_TXCLEAR);
		bWriteStat = WriteFile(hCom, szBuffer, count, &dwRealSend, &m_osWrite);
		if (!bWriteStat)
		{
			if (GetLastError() == ERROR_IO_PENDING)
			{
				while (!GetOverlappedResult(hCom, &m_osWrite, &dwRealSend, FALSE))
				{

					if (GetLastError() == ERROR_IO_INCOMPLETE)
					{
						//cout<<"写未完成,继续!"<     
						continue;
					}
				}
				//WaitForSingleObject(m_osWrite.hEvent, 1000);
				//GetOverlappedResult(hCom, &m_osWrite, (DWORD*)(&count), TRUE);
				return count;
			}
			return 0;
		}
	}
	return count;
#endif
}
开发者ID:ylzhu,项目名称:cdtWifiDeviceCtrlSystem,代码行数:52,代码来源:SerialPortControl.cpp

示例11: CheckReadyToWrite

void CheckReadyToWrite(UART_PORT port)
{
    COMSTAT	comstat;
    DWORD	errors;
    if(ClearCommError(UARTHandle[port], &errors, &comstat))
    {
        if(comstat.fCtsHold==0 && comstat.fXoffHold==0 && comstat.fXoffSent==0)
        {            
			UART_sendilm(port, MSG_ID_UART_READY_TO_WRITE_IND);
            breadytowrite[port] = FALSE;
        }
    }            
}
开发者ID:12019,项目名称:mtktest,代码行数:13,代码来源:w32_uart.c

示例12: CheckReadyToRead

void CheckReadyToRead(UART_PORT port)
{
    COMSTAT	comstat;
    DWORD	errors;
    if(ClearCommError(UARTHandle[port], &errors, &comstat))
    {
        if(comstat.cbInQue)        
        {
            UART_sendilm(port, MSG_ID_UART_READY_TO_READ_IND);
            breadytoread[port] = FALSE;
        }
    }        
}
开发者ID:12019,项目名称:mtktest,代码行数:13,代码来源:w32_uart.c

示例13: ndiSerialBreak

int ndiSerialBreak(HANDLE serial_port)
{
  DWORD dumb;

  ClearCommError(serial_port,&dumb,NULL);       /* clear error */
  PurgeComm(serial_port,PURGE_TXCLEAR|PURGE_RXCLEAR); /* clear buffers */

  SetCommBreak(serial_port);
  Sleep(300);                            /* hold break for 0.3 seconds */ 
  ClearCommBreak(serial_port);

  return 0;
}
开发者ID:Beastmaster,项目名称:AIGS,代码行数:13,代码来源:ndicapi_serial.c

示例14: Java_com_fazecast_jSerialComm_SerialPort_bytesAvailable

JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_bytesAvailable(JNIEnv *env, jobject obj, jlong serialPortFD)
{
	HANDLE serialPortHandle = (HANDLE)serialPortFD;
	if (serialPortHandle == INVALID_HANDLE_VALUE)
		return -1;

	COMSTAT commInfo;
	if (!ClearCommError(serialPortHandle, NULL, &commInfo))
		return -1;
	DWORD numBytesAvailable = commInfo.cbInQue;

	return (jint)numBytesAvailable;
}
开发者ID:psbs,项目名称:jSerialComm,代码行数:13,代码来源:SerialPort_Windows.c

示例15: xbee_ser_rx_used

int xbee_ser_rx_used( xbee_serial_t *serial)
{
	COMSTAT	stat;

	XBEE_SER_CHECK( serial);

	if (ClearCommError( serial->hCom, NULL, &stat))
	{
		return (int) stat.cbInQue;
	}

	return 0;
}
开发者ID:Charhong,项目名称:xbee_ansic_library,代码行数:13,代码来源:xbee_serial_win32.c


注:本文中的ClearCommError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。