當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。