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


C++ GetCommTimeouts函数代码示例

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


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

示例1: RCX_open

int RCX_open(int type, char *portname){
  //Opens the connections to the RCX via tower on serial or usb port.
  //type 1: serial port, type 2: USB port
  //portname for serial port is "COM1" for example
  //portname for USB port is "\\\\.\\LEGOTOWER1" for example
  //returns 0 if failed, 1 if successful

  if (type==1){//open serial port
    RCX_port = CreateFileA("COM6", GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, 0);

    if (RCX_port == INVALID_HANDLE_VALUE) return(0);

    //set data protocol format
    GetCommState(RCX_port,&dcb);
    FillMemory(&dcb, sizeof(dcb), 0);
    dcb.DCBlength = sizeof(dcb);
    dcb.BaudRate=CBR_2400;
    dcb.fBinary=1;
    dcb.fParity=1;
    dcb.fDtrControl=DTR_CONTROL_ENABLE;
    dcb.fRtsControl=RTS_CONTROL_ENABLE;
    dcb.ByteSize=8;
    dcb.Parity=ODDPARITY;
    dcb.StopBits=ONESTOPBIT;
    if (!SetCommState(RCX_port, &dcb)){
      RCX_close();
      return(0);
    }


    GetCommTimeouts(RCX_port,&tout);
    tout.ReadIntervalTimeout=250;
    tout.ReadTotalTimeoutConstant=10;
    tout.ReadTotalTimeoutMultiplier=10;
    tout.WriteTotalTimeoutConstant=10;
    tout.WriteTotalTimeoutMultiplier=10;
    SetCommTimeouts(RCX_port,&tout);

    SetupComm(RCX_port,65536,65536);
  } else { //type 2: open USB port
    RCX_port = CreateFileA(portname, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH | FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING, 0);
    if (RCX_port == INVALID_HANDLE_VALUE) return(0);

    GetCommTimeouts(RCX_port,&tout);
    tout.ReadIntervalTimeout=250;
    tout.ReadTotalTimeoutConstant=10;
    tout.ReadTotalTimeoutMultiplier=10;
    tout.WriteTotalTimeoutConstant=10;
    tout.WriteTotalTimeoutMultiplier=10;
    SetCommTimeouts(RCX_port,&tout);
  }


  return(1);
}
开发者ID:rkovessy,项目名称:VeWalker,代码行数:55,代码来源:rcx21.cpp

示例2: pollImpl

int SerialPortImpl::pollImpl(char* buffer, std::size_t size, const Poco::Timespan& timeout)
{
	COMMTIMEOUTS prevCTO;
	if (!GetCommTimeouts(_handle, &prevCTO))
	{
		throw Poco::IOException("error getting serial port timeouts");
	}

	COMMTIMEOUTS cto;
	cto.ReadIntervalTimeout         = CHARACTER_TIMEOUT;
	cto.ReadTotalTimeoutConstant    = static_cast<DWORD>(timeout.totalMilliseconds());
	cto.ReadTotalTimeoutMultiplier  = 0;
	cto.WriteTotalTimeoutConstant   = MAXDWORD;
	cto.WriteTotalTimeoutMultiplier = 0;
	if (!SetCommTimeouts(_handle, &cto))
	{
		throw Poco::IOException("error setting serial port timeouts on serial port");
	}

	try
	{
		DWORD bytesRead = 0;
		if (!ReadFile(_handle, buffer, size, &bytesRead, NULL))
		{
			throw Poco::IOException("failed to read from serial port");
		}
		SetCommTimeouts(_handle, &prevCTO);
		return (bytesRead == 0) ? -1 : bytesRead;
	}
	catch (...)
	{
		SetCommTimeouts(_handle, &prevCTO);
		throw;
	}
}
开发者ID:weinzierl-engineering,项目名称:baos,代码行数:35,代码来源:SerialPort_WIN32.cpp

示例3: initSerial

/**
 * @brief This function initializes the serial port for both directions (reading/writing) with fixed parameters:
 * \n baud=38400, parity=N, data=8, stop=1
 * @param *serialPort is a pointer to the name of the serial port
 * @return TRUE if success, FALSE in case of error.
 */
BOOL initSerial(CHAR *serialPort)
{
	COMMTIMEOUTS timeouts;
	int rc;
	DCB dcbStruct;
	CHAR msgTextBuf[256];

	// open the comm port.
	comPort = CreateFile(serialPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, NULL);
	if (comPort == INVALID_HANDLE_VALUE)
	{
		printf("Unable to open %s. \n", serialPort);
		return FALSE;
	}

	// get the current DCB, and adjust a few bits to our liking.
	memset(&dcbStruct, 0, sizeof(dcbStruct));

	dcbStruct.DCBlength = sizeof(dcbStruct);
	// printf("dcbStruct.DCBlength(): %ld \n", dcbStruct.DCBlength);

	rc = GetCommState(comPort, &dcbStruct);
	if (rc == 0)
	{
		printf("\nGetCommState(): ");
		printf(getLastErrorText(msgTextBuf, sizeof(msgTextBuf)));
		return FALSE;
	}

	// http://msdn.microsoft.com/en-us/library/windows/desktop/aa363143(v=vs.85).aspx
	BuildCommDCB("baud=38400 parity=N data=8 stop=1", &dcbStruct);

	rc = SetCommState(comPort, &dcbStruct);
	// If the function fails, the return value is zero.
	if (rc == 0)
	{
		printf("\nSetCommState(): ");
		printf(getLastErrorText(msgTextBuf, sizeof(msgTextBuf)));
		return FALSE;
	}

	// Retrieve the timeout parameters for all read and write operations on the port.
	GetCommTimeouts (comPort, &timeouts);

	timeouts.ReadIntervalTimeout = 250;
	timeouts.ReadTotalTimeoutMultiplier = 1;
	timeouts.ReadTotalTimeoutConstant = 500;
	timeouts.WriteTotalTimeoutMultiplier = 1;
	timeouts.WriteTotalTimeoutConstant = 2500;

	rc = SetCommTimeouts(comPort, &timeouts);          // If the function fails, the return value is zero.
	if (rc == 0)
	{
		printf("\nSetCommTimeouts(): ");
		printf(getLastErrorText(msgTextBuf, sizeof(msgTextBuf)));
		return FALSE;
	}

	return TRUE;
}
开发者ID:pszyjaciel,项目名称:myEthernut,代码行数:66,代码来源:mySerial.c

示例4: serialGetC

int serialGetC(HANDLE fd, uint8_t* c, int timeout)
{
	COMMTIMEOUTS timeouts;
	unsigned long res;
	COMSTAT comStat;
	DWORD errors;

	if(!ClearCommError(fd, &errors, &comStat)) {
		printErr("could not reset comm errors", GetLastError());
		return -1;
	}

	if(!GetCommTimeouts(fd, &timeouts)) {
		printErr("error getting comm timeouts", GetLastError());
		return -1;
	}
	timeouts.ReadIntervalTimeout = timeout;
	timeouts.ReadTotalTimeoutConstant = timeout;
	timeouts.ReadTotalTimeoutMultiplier = 10;
	if(!SetCommTimeouts(fd, &timeouts)) {
		printErr("error setting comm timeouts", GetLastError());
		return -1;
	}

	if(!ReadFile(fd, c, 1, &res, NULL)) {
		printErr("error reading from serial port", GetLastError());
		return -1;
	}

	if(res != 1)
		return -1;

	return *c;
}
开发者ID:JiaoXianjun,项目名称:osmo-sdr,代码行数:34,代码来源:serial.c

示例5: openPort

/** open a serial port */
static HANDLE openPort(const char *port,int baud)
{
	HANDLE       h;
	DCB          dcb;
	COMMTIMEOUTS tmo;
	int          status;

	/* open the port */
	h = CreateFile( port,  
                    GENERIC_READ | GENERIC_WRITE, 
                    0, 
                    0, 
                    OPEN_EXISTING,
                    0,
                    0);
	if (h == INVALID_HANDLE_VALUE) {
		/* quit on error */
		return h;
	}
   

	/* read current configuration */
   status = GetCommState(h,&dcb);
   if (status == 0) {
	   CloseHandle(h);
	   return INVALID_HANDLE_VALUE;
   }

   /* set the baud rate and other parameters */
   dcb.BaudRate = baud;
   dcb.ByteSize = 8;
   dcb.Parity   = NOPARITY; 
   dcb.StopBits = ONESTOPBIT;

   /* set configuration */
   status = SetCommState(h, &dcb);
   if (status == 0) {
	   CloseHandle(h);
	   return INVALID_HANDLE_VALUE;
   }

   /* read timeout configuration */
   status = GetCommTimeouts(h,&tmo);
   if (status == 0) {
	   CloseHandle(h);
	   return INVALID_HANDLE_VALUE;
   }

   /* set to indefinite blocking */
   tmo.ReadIntervalTimeout        = 0;
   tmo.ReadTotalTimeoutConstant   = 0;
   tmo.ReadTotalTimeoutMultiplier = 0;
   status = SetCommTimeouts(h,&tmo);
   if (status == 0) {
	   CloseHandle(h);
	   return INVALID_HANDLE_VALUE;
   }

	return h;
}
开发者ID:amdoolittle,项目名称:APRS_Projects,代码行数:61,代码来源:wingps.c

示例6: setTimeout

		virtual bool setTimeout (int iTotalReadTimeout)
		{
			if (INVALID_HANDLE_VALUE == hComm)
				return (TRUE);

			if (!GetCommTimeouts(this->hComm, &timeouts_alt)) 
			{
				this->close ();
				MessageBox (NULL, "could not open comport!\nGetCommTimeouts()",
					NULL, NULL);
				return (FALSE);
			}

			COMMTIMEOUTS timeouts;
			timeouts.ReadIntervalTimeout = MAXDWORD ;
			timeouts.ReadTotalTimeoutMultiplier = MAXDWORD ;
			timeouts.ReadTotalTimeoutConstant = (DWORD) iTotalReadTimeout;
			timeouts.WriteTotalTimeoutMultiplier = 1000;
			timeouts.WriteTotalTimeoutConstant = 1000;

			if (!SetCommTimeouts(hComm, &timeouts))
				return (FALSE);

			return(TRUE);
		}
开发者ID:berak,项目名称:e6,代码行数:25,代码来源:SerialPort.cpp

示例7: RS485_Initialize

/****************************************************************************
* DESCRIPTION: Initializes the RS485 hardware and variables, and starts in
*              receive mode.
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
void RS485_Initialize(
    void)
{
    RS485_Handle =
        CreateFile(RS485_Port_Name, GENERIC_READ | GENERIC_WRITE, 0, 0,
        OPEN_EXISTING,
        /*FILE_FLAG_OVERLAPPED */ 0,
        0);
    if (RS485_Handle == INVALID_HANDLE_VALUE) {
        fprintf(stderr, "Unable to open %s\n", RS485_Port_Name);
        RS485_Print_Error();
        exit(1);
    }
    if (!GetCommTimeouts(RS485_Handle, &RS485_Timeouts)) {
        RS485_Print_Error();
    }
    RS485_Configure_Status();
#if PRINT_ENABLED
    fprintf(stderr, "RS485 Interface: %s\n", RS485_Port_Name);
#endif

    atexit(RS485_Cleanup);

    return;
}
开发者ID:charador,项目名称:PropRes_Receiver,代码行数:32,代码来源:rs485.c

示例8: CreateFile

HANDLE IO::openComm() {
	h = CreateFile(TEXT("COM3"), FILE_SHARE_READ | FILE_SHARE_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
	if (INVALID_HANDLE_VALUE == h) {
		int err = GetLastError();
		return h;
	}

	COMMTIMEOUTS timeouts;
	GetCommTimeouts(h, &timeouts);
	timeouts.ReadIntervalTimeout = 0;
	timeouts.ReadTotalTimeoutMultiplier = 0;
	timeouts.ReadTotalTimeoutConstant = 0;
	timeouts.WriteTotalTimeoutMultiplier = 0;
	timeouts.WriteTotalTimeoutConstant = 0;
	SetCommTimeouts(h, &timeouts);

	//设置串口配置信息
	DCB dcb;
	if (!GetCommState(h, &dcb))
	{
		cout << "GetCommState() failed" << endl;
		CloseHandle(h);
		return INVALID_HANDLE_VALUE;
	}
	int nBaud = 57600;
	dcb.DCBlength = sizeof(DCB);
	dcb.BaudRate = nBaud;//波特率为9600
	dcb.Parity = 0;//校验方式为无校验
	dcb.ByteSize = 8;//数据位为8位
	dcb.StopBits = ONESTOPBIT;//停止位为1位
	if (!SetCommState(h, &dcb))
	{
		cout << "SetCommState() failed" << endl;
		CloseHandle(h);
		return INVALID_HANDLE_VALUE;
	}

	//设置读写缓冲区大小
	static const int g_nZhenMax = 16;//32768;
	if (!SetupComm(h, g_nZhenMax, g_nZhenMax))
	{
		cout << "SetupComm() failed" << endl;
		CloseHandle(h);
		return INVALID_HANDLE_VALUE;
	}

	//清空缓冲
	PurgeComm(h, PURGE_RXCLEAR | PURGE_TXCLEAR);

	//清除错误
	DWORD dwError;
	COMSTAT cs;
	if (!ClearCommError(h, &dwError, &cs))
	{
		cout << "ClearCommError() failed" << endl;
		CloseHandle(h);
		return INVALID_HANDLE_VALUE;
	}
	return h;
}
开发者ID:variantf,项目名称:quadrotor,代码行数:60,代码来源:IO.cpp

示例9: TRACE_FUN

   bool CSerialLine::SetMultiplierTimeOuts( unsigned int aReadTimeOut, unsigned int aWriteTimeOut )const
   {
      TRACE_FUN( Routine, "CSerialLine::SetMultiplyTimeOuts" );

      bool ret( false );

      if( isOpen() )
      {
         #ifdef __WIN32__
            COMMTIMEOUTS commTimeOuts;

            if( GetCommTimeouts( _hFile, &commTimeOuts ) )
            {
               TraceRoutine << "commTimeOuts.ReadTotalTimeoutMultiplier: " << commTimeOuts.ReadTotalTimeoutMultiplier << std::endl;
               TraceRoutine << "commTimeOuts.WriteTotalTimeoutMultiplier: " << commTimeOuts.WriteTotalTimeoutMultiplier << std::endl;

               commTimeOuts.ReadTotalTimeoutMultiplier = aReadTimeOut;
               commTimeOuts.WriteTotalTimeoutMultiplier = aWriteTimeOut;

               ret = SetCommTimeouts( _hFile, &commTimeOuts );
            }
         #endif
      }
      return ret;
   }
开发者ID:L2-Max,项目名称:l2ChipTuner,代码行数:25,代码来源:l2SerialLine.cpp

示例10: sconfig

// configure serial port
bool sconfig(char* fmt) {
  DCB dcb;
  COMMTIMEOUTS cmt;
  // clear dcb  
  memset(&dcb,0,sizeof(DCB));
  dcb.DCBlength=sizeof(DCB);
  // configure serial parameters
  if(!BuildCommDCB(fmt,&dcb)) return false;
  dcb.fOutxCtsFlow=0;
  dcb.fOutxDsrFlow=0;
  dcb.fDtrControl=0;
  dcb.fOutX=0;
  dcb.fInX=0;
  dcb.fRtsControl=0;
  if(!SetCommState(h_serial,&dcb)) return false;
  // configure buffers
  if(!SetupComm(h_serial,1024,1024)) return false;
  // configure timeouts 
  GetCommTimeouts(h_serial,&cmt);
  memcpy(&restore,&cmt,sizeof(cmt));
  cmt.ReadIntervalTimeout=100;
  cmt.ReadTotalTimeoutMultiplier=100;
  cmt.ReadTotalTimeoutConstant=100;
  cmt.WriteTotalTimeoutConstant=100;
  cmt.WriteTotalTimeoutMultiplier=100;
  if(!SetCommTimeouts(h_serial,&cmt)) return false;
  return true;
}
开发者ID:stg,项目名称:PicOptic,代码行数:29,代码来源:serial.c

示例11: CreateFileW

ComPort::ComPort(wchar_t *portName, unsigned int baund)
{
    hCOM = CreateFileW(portName,
                       GENERIC_READ | GENERIC_WRITE,
                       0,  NULL, OPEN_EXISTING,  0,  NULL);

    if(hCOM == INVALID_HANDLE_VALUE)
        throw std::runtime_error ("Unable to open port ");
    DCB dcb={0};
    COMMTIMEOUTS CommTimeouts;
    dcb.DCBlength = sizeof(DCB);
    GetCommState(hCOM, &dcb);

    dcb.BaudRate = CBR_115200;
    dcb.ByteSize = 8;
    dcb.Parity = NOPARITY;
    dcb.StopBits = ONESTOPBIT;
    SetCommState(hCOM, &dcb);

    GetCommTimeouts(hCOM,&CommTimeouts);
    CommTimeouts.ReadIntervalTimeout = 100;
    CommTimeouts.ReadTotalTimeoutMultiplier = 1;
    CommTimeouts.ReadTotalTimeoutConstant = 100;
    CommTimeouts.WriteTotalTimeoutMultiplier = 0;
    CommTimeouts.WriteTotalTimeoutConstant = 0;
    SetCommTimeouts(hCOM,&CommTimeouts);
    FlushFileBuffers(hCOM);
    DWORD Errors;
    COMSTAT ComState;
    ClearCommError(hCOM, &Errors, &ComState);
}
开发者ID:KonstantinChizhov,项目名称:AvrProjects,代码行数:31,代码来源:comport.cpp

示例12: GetCommState

//---------------------------------------------------------------------------
void __fastcall TCommThread::Open()
{
        if(Connected==false)
        {
                //Open device
                DeviceHandle=CreateFile(        DeviceName.c_str(),
                                                GENERIC_READ|GENERIC_WRITE,
                                                FILE_SHARE_DELETE,
                                                NULL,
                                                OPEN_EXISTING,
                                                FILE_ATTRIBUTE_TEMPORARY|FILE_FLAG_DELETE_ON_CLOSE,
                                                NULL
                                        );

                if(DeviceHandle!=INVALID_HANDLE_VALUE)
                {
                        //Make backup and set DCB of open device
                        GetCommState(DeviceHandle,&OriginalDCB);
                        SetCommState(DeviceHandle,&MyDCB);

                        //Make backup and set COMMTIMEOUTS of open device
                        GetCommTimeouts(DeviceHandle,&OriginalTimeouts);
                        SetCommTimeouts(DeviceHandle,&MyTimeouts);

                        SetupComm(DeviceHandle,1024*ReceiveQueue,1024*TransmitQueue);

                        //Resume Thread
                        if(this->Suspended)
                                Resume();
                        Connected=true;
                }//if
        }//if
}
开发者ID:JaconsMorais,项目名称:repcomputaria,代码行数:34,代码来源:CommThread_Unit.cpp

示例13: CreateFile

static SERIALPORT *serial_open(const char *device){
    HANDLE fh;
    DCB dcb={sizeof(DCB)};
    COMMTIMEOUTS timeouts;
    SERIALPORT *port;

    fh = CreateFile(device,GENERIC_READ|GENERIC_WRITE,0,NULL,
      OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
    if (!fh) return NULL;

    port = malloc(sizeof(SERIALPORT));
    ZeroMemory(port, sizeof(SERIALPORT));
    port->fh = fh;

    /* save current port settings */
    GetCommState(fh,&port->dcb_save);
    GetCommTimeouts(fh,&port->timeouts_save);

    dcb.DCBlength=sizeof(DCB);
    BuildCommDCB("96,n,8,1",&dcb);
    SetCommState(fh,&dcb);

    ZeroMemory(&timeouts,sizeof(timeouts));
    timeouts.ReadTotalTimeoutConstant=1;
    timeouts.WriteTotalTimeoutConstant=1;
    SetCommTimeouts(fh,&timeouts);

    serial_flush(port);

    return port;
}
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:31,代码来源:freeglut_input_devices.c

示例14: GetCommState

BOOL CPSerialPort::OpenPort(LPCTSTR Port,int BaudRate,int StopBits,int Parity,int DataBits,LPDataArriveProc proc,DWORD userdata)
{
	m_lpDataArriveProc=proc;
	m_dwUserData=userdata;

	if(m_hComm==INVALID_HANDLE_VALUE)
	{
		m_hComm=CreateFile(Port,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
		if(m_hComm==INVALID_HANDLE_VALUE )
		{
//			AfxMessageBox(_T("ERROR 104:无法打开端口!请检查是否已被占用。"));
			return FALSE;
		}
		GetCommState(m_hComm,&dcb);
		dcb.BaudRate=BaudRate;
		dcb.ByteSize=DataBits;
		dcb.Parity=Parity;
		dcb.StopBits=StopBits;
		dcb.fParity=FALSE;
		dcb.fBinary=TRUE;
		dcb.fDtrControl=0;
		dcb.fRtsControl=0;
		dcb.fOutX=dcb.fInX=dcb.fTXContinueOnXoff=0;
		
		//设置状态参数
		SetCommMask(m_hComm,EV_RXCHAR);		
		SetupComm(m_hComm,1024,1024);		
		if(!SetCommState(m_hComm,&dcb))
		{
			AfxMessageBox(_T("ERROR 105:无法按当前参数配置端口,请检查参数!"));
			PurgeComm(m_hComm,PURGE_TXCLEAR|PURGE_RXCLEAR);
			ClosePort();
			return FALSE;
		}
		
		//设置超时参数
		GetCommTimeouts(m_hComm,&CommTimeOuts);		
		CommTimeOuts.ReadIntervalTimeout=100;
		CommTimeOuts.ReadTotalTimeoutMultiplier=1;
		CommTimeOuts.ReadTotalTimeoutConstant=100;
		CommTimeOuts.WriteTotalTimeoutMultiplier=1;
		CommTimeOuts.WriteTotalTimeoutConstant=100;		
		if(!SetCommTimeouts(m_hComm,&CommTimeOuts))
		{
			AfxMessageBox(_T("ERROR 106:无法设置超时参数!"));
			PurgeComm(m_hComm,PURGE_TXCLEAR|PURGE_RXCLEAR);
			ClosePort();
			return FALSE;
		}
		
		PurgeComm(m_hComm,PURGE_TXCLEAR|PURGE_RXCLEAR);		
		Activate();
		return TRUE;		
	}
	
	return TRUE;
}
开发者ID:Biotron,项目名称:kpgweigher,代码行数:57,代码来源:PSerialPort.cpp

示例15: find_smartphone_port

//-------------------------------------------------------------------------
// Initialize TRK connection over a serial port.
// Returns success.
bool metrotrk_t::init(int port)
{
  sseq = 0;

  if ( port == DEBUGGER_PORT_NUMBER )
  {
    int p = find_smartphone_port();
    if ( p > 0 )
    {
      port = p;
      msg("Using COM%d: to communicate with the smartphone...\n", port);
    }
    else
    {
      warning("Could not autodetect the smartphone port.\n"
              "Please specify it manually in the process options");
    }
  }

  char name[32];
  qsnprintf(name, sizeof(name), "\\\\.\\COM%d", port);

  qstring friendly_name;
  if ( !is_serial_port_present(port, &friendly_name) )
  {
      if ( askyn_c(0,
                   "HIDECANCEL\n"
                   "Serial port COM%d seems to be unavailable. Do you want to proceed?",
                   port ) <= 0 )
      {
        SetLastError(ERROR_DEVICE_NOT_CONNECTED);
        return false;
      }
  }
  msg("Opening serial port %s: (%s)...\n", &name[4], friendly_name.c_str());

  // port exists, open it
  hp = CreateFile(name, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
  if ( hp == INVALID_HANDLE_VALUE )
    return false;
  DCB dcb;
  memset(&dcb, 0, sizeof(dcb));
  dcb.DCBlength = sizeof(dcb);
  dcb.BaudRate = CBR_115200;
  dcb.fBinary = true;
  dcb.ByteSize = 8;
  dcb.Parity = NOPARITY;
  dcb.StopBits = ONESTOPBIT;
  if ( !SetCommState(hp, &dcb) )
  {
    CloseHandle(hp);
    return false;
  }
  GetCommTimeouts(hp, &ct);
  return true;
}
开发者ID:nealey,项目名称:vera,代码行数:59,代码来源:metrotrk.cpp


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