• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ClearCommError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: BytesInTxQueue

// Returns the number of bytes in the transmission queue.
int JHCommBase::BytesInTxQueue()
{
	COMSTAT cs;
	DWORD er;
	if (hPort != INVALID_HANDLE_VALUE)
	{
		if (ClearCommError(hPort, &er, &cs))
		{
			return cs.cbOutQue;
		}
	}
	return -1;
}
开发者ID:radioflash,项目名称:Winsh.lua,代码行数:14,代码来源:CommBaseC.cpp


示例17: serial_rxlen

/*----------------------------------------------------------------------------*/
unsigned serial_rxlen(int fd)
{
  HANDLE h;
  DWORD err;
  COMSTAT stat;
  h = get_h(fd);
  if(h)
  {
    ClearCommError(h, &err, &stat);
    return stat.cbInQue;
  }
  return 0;
}
开发者ID:olegyurchenko,项目名称:dda-control,代码行数:14,代码来源:pc_serial.c


示例18: CheckErrors

void CDirectSerial::CheckErrors() {
	
	DWORD errors=0;
	// check for errors
	if (ClearCommError (hCom, &errors, NULL))
		if (errors & (CE_BREAK | CE_FRAME | CE_RXPARITY)) {
			Bit8u errreg = 0;
			if (errors & CE_BREAK) errreg |= LSR_RX_BREAK_MASK;
			if (errors & CE_FRAME) errreg |= LSR_FRAMING_ERROR_MASK;
			if (errors & CE_RXPARITY) errreg |= LSR_PARITY_ERROR_MASK;
			receiveError (errreg);
		}
}
开发者ID:crutchwalkfactory,项目名称:motocakerteam,代码行数:13,代码来源:directserial_win32.cpp


示例19: ser_windows_wait_handle

static void
ser_windows_wait_handle (struct serial *scb, HANDLE *read, HANDLE *except)
{
    struct ser_windows_state *state;
    COMSTAT status;
    DWORD errors;
    HANDLE h = (HANDLE) _get_osfhandle (scb->fd);

    state = scb->state;

    *except = state->except_event;
    *read = state->ov.hEvent;

    if (state->in_progress)
        return;

    /* Reset the mask - we are only interested in any characters which
       arrive after this point, not characters which might have arrived
       and already been read.  */

    /* This really, really shouldn't be necessary - just the second one.
       But otherwise an internal flag for EV_RXCHAR does not get
       cleared, and we get a duplicated event, if the last batch
       of characters included at least two arriving close together.  */
    if (!SetCommMask (h, 0))
        warning (_("ser_windows_wait_handle: reseting mask failed"));

    if (!SetCommMask (h, EV_RXCHAR))
        warning (_("ser_windows_wait_handle: reseting mask failed (2)"));

    /* There's a potential race condition here; we must check cbInQue
       and not wait if that's nonzero.  */

    ClearCommError (h, &errors, &status);
    if (status.cbInQue > 0)
    {
        SetEvent (state->ov.hEvent);
        return;
    }

    state->in_progress = 1;
    ResetEvent (state->ov.hEvent);
    state->lastCommMask = -2;
    if (WaitCommEvent (h, &state->lastCommMask, &state->ov))
    {
        gdb_assert (state->lastCommMask & EV_RXCHAR);
        SetEvent (state->ov.hEvent);
    }
    else
        gdb_assert (GetLastError () == ERROR_IO_PENDING);
}
开发者ID:sergiodj,项目名称:gdb-sergio,代码行数:51,代码来源:ser-mingw.c


示例20: while

int CSeries::SerRead(BYTE *pszBuf, int RecvCnt, int TimeOut)
{
	BOOL        fReadStat;
	DWORD       OldCount,Count,dwReaded, dwError;
	DWORD       dwErrorFlags;
	COMSTAT		ComStat;
	DWORD		i=0;

	OldCount=GetTickCount();
	while (1)
	{
		ClearCommError(m_CommPort, &dwErrorFlags, &ComStat);
		fReadStat = ReadFile(m_CommPort, pszBuf+i, RecvCnt-i,
			&dwReaded, NULL);

		if (!fReadStat)
		{
			dwError = GetLastError();
			// some other error occurred
			ClearCommError(m_CommPort, &dwErrorFlags, &ComStat);
			return -1;
		}

		if(dwReaded ==0)
		{
			Count=GetTickCount();
			if(Count-OldCount>=(unsigned long)TimeOut) //修改:timeout为int型 ,强制转换为UL
				return -2;
			Sleep(10);
		}
		else
		{
			i += dwReaded;	
			if (i >= (unsigned long)RecvCnt)//修改:timeout为int型 ,强制转换为UL
				return 0;
		}
	} 
}
开发者ID:colin-zhang,项目名称:SmartPad_Console_Tool,代码行数:38,代码来源:Cserial.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ClearCondition函数代码示例发布时间:2022-05-30
下一篇:
C++ ClearCharmInfoFlags函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap