这篇教程C++ GetCommTimeouts函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中GetCommTimeouts函数的典型用法代码示例。如果您正苦于以下问题:C++ GetCommTimeouts函数的具体用法?C++ GetCommTimeouts怎么用?C++ GetCommTimeouts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了GetCommTimeouts函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: RCX_openint 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,
示例2: pollImplint 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,
示例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,
示例4: serialGetCint 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,
示例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,
示例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,
示例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,
示例8: CreateFileHANDLE 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,
示例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,
示例10: sconfig// configure serial portbool 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,
示例11: CreateFileWComPort::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,
示例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,
示例13: CreateFilestatic 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,
示例14: GetCommStateBOOL 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,
示例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,
示例16: ASSERTvoid CSerialPort::GetTimeouts(COMMTIMEOUTS& timeouts){ ASSERT(IsOpen()); if (!GetCommTimeouts(m_hComm, &timeouts)) { TRACE(_T("Failed in call to GetCommTimeouts/n")); AfxThrowSerialException(); }}
开发者ID:freegroup,项目名称:DigitalSimulator,代码行数:10,
示例17: GetCommTimeoutsvpr::Uint32 SerialPortImplWin32::read_i(void* buffer, const vpr::Uint32 length, const vpr::Interval& timeout){ unsigned long bytes; // Shouldn't be setting this every read, but don't have any other way of // specifying the timeout. if ( vpr::Interval::NoTimeout != timeout ) { COMMTIMEOUTS t; GetCommTimeouts(mHandle, &t); t.ReadTotalTimeoutConstant = (int)timeout.msec(); SetCommTimeouts(mHandle, &t); } if ( ! ReadFile(mHandle, buffer, length, &bytes, NULL) ) { std::stringstream msg_stream; msg_stream << "Failed to read from serial port " << mName << ": " << getErrorMessageWithCode(GetLastError()); throw IOException(msg_stream.str(), VPR_LOCATION); } //Now set the timeout back if ( vpr::Interval::NoTimeout != timeout ) { COMMTIMEOUTS t; GetCommTimeouts(mHandle, &t); t.ReadTotalTimeoutConstant = (int)mCurrentTimeout*100; SetCommTimeouts(mHandle, &t); } // XXX: Does reading 0 bytes really indicate a timeout? if ( bytes == 0 ) { std::stringstream msg_stream; msg_stream << "Timeout while attempting to read from serial port " << mName; throw TimeoutException(msg_stream.str(), VPR_LOCATION); } return bytes;}
开发者ID:rpavlik,项目名称:vrjuggler-2.2-debs,代码行数:43,
示例18: set_timeoutstatic void set_timeout(urg_serial_t *serial, int timeout){ COMMTIMEOUTS timeouts; GetCommTimeouts(serial->hCom, &timeouts); timeouts.ReadIntervalTimeout = (timeout == 0) ? MAXDWORD : 0; timeouts.ReadTotalTimeoutConstant = timeout; timeouts.ReadTotalTimeoutMultiplier = 0; SetCommTimeouts(serial->hCom, &timeouts);}
开发者ID:OspreyX,项目名称:urg_c,代码行数:11,
示例19: 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,
示例20: CreateFileBOOL CECGDlg::OpenPort(LPCTSTR Port, int BaudRate, int DataBits, int Parity, int StopBits, HANDLE &hComm){ DCB dcb; BOOL ret; COMMTIMEOUTS CommTimeOuts; hComm = CreateFile(Port, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); if(hComm == INVALID_HANDLE_VALUE) { UpdateStatus(L"Unable to open the serial port or the serial port has already been opened! Please check if the port is already in use", ADDSTR2STATUS); return FALSE; } dcb.DCBlength = sizeof (dcb); ret = GetCommState(hComm, &dcb); if( !ret) { UpdateStatus(L"Unable to get Comm. State", ADDSTR2STATUS); ClosePort(hComm); return FALSE; } dcb.BaudRate = BaudRate; dcb.fParity = FALSE; // Parity check disabled dcb.fNull = FALSE; dcb.ByteSize = DataBits; dcb.Parity = Parity; dcb.StopBits = StopBits; ret = SetCommState(hComm, &dcb); if( !ret ) { UpdateStatus(L"Unable to configure serial port. Please check the port configuration! Serial port is closed", ADDSTR2STATUS); ClosePort(hComm); return FALSE; } GetCommTimeouts(hComm, &CommTimeOuts); CommTimeOuts.ReadIntervalTimeout = 100; // Max text receiving interval CommTimeOuts.ReadTotalTimeoutMultiplier = 1; CommTimeOuts.ReadTotalTimeoutConstant = 100; // Number of timeouts for reading data CommTimeOuts.WriteTotalTimeoutMultiplier = 0; CommTimeOuts.WriteTotalTimeoutConstant = 0; ret = SetCommTimeouts(hComm, &CommTimeOuts); if ( !ret ) { UpdateStatus(L"Unable to set timeout parameter! Serial port is closed!", ADDSTR2STATUS); ClosePort(hComm); return FALSE; } PurgeComm(hComm, PURGE_TXCLEAR | PURGE_RXCLEAR); return TRUE;}
开发者ID:Michael-Lu,项目名称:ECG_backward,代码行数:53,
示例21: GetPortNamebool Serial::Open(){ if (_file) return false; std::wstring path = L"////.//"; path += GetPortName(); HANDLE file = CreateFile(path.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, nullptr); if (!file || file == INVALID_HANDLE_VALUE) { AfxMessageBox(L"CreateFile failed"); return false; } DCB dcb; ::memset(&dcb, 0, sizeof dcb); dcb.fBinary = true; dcb.BaudRate = UsbSpeed; dcb.ByteSize = 8; if (!SetCommState(file, &dcb)) { AfxMessageBox(L"SetCommState failed"); return false; } COMMTIMEOUTS timeouts; if (!GetCommTimeouts(file, &timeouts)) { AfxMessageBox(L"GetCommTimeouts failed"); return false; } //timeouts.ReadIntervalTimeout = 5; //timeouts.ReadTotalTimeoutConstant = 5; //timeouts.ReadTotalTimeoutMultiplier = 10; timeouts.ReadIntervalTimeout = 1; timeouts.ReadTotalTimeoutConstant = 1; timeouts.ReadTotalTimeoutMultiplier = 1; if (!SetCommTimeouts(file, &timeouts)) { AfxMessageBox(L"SetCommTimeouts failed"); return false; } _file = file; _abort = false; _thread = std::thread(&Serial::Go, this); return true;}
开发者ID:molip,项目名称:Oscilloscope,代码行数:52,
示例22: ConfigSerialPortDWORD __stdcall ConfigSerialPort(HANDLE h, DWORD dwBaudRate, DWORD dwTimeOutInSec){ if (!SetupComm(h, 1024, 1024)) { return ::GetLastError(); } DCB dcbConfig; if (GetCommState(h, &dcbConfig)) /* Configuring Serial Port Settings */ { dcbConfig.BaudRate = dwBaudRate; dcbConfig.ByteSize = 8; dcbConfig.Parity = NOPARITY; dcbConfig.StopBits = ONESTOPBIT; dcbConfig.fBinary = TRUE; dcbConfig.fParity = TRUE; } else { return ::GetLastError(); } if (!SetCommState(h, &dcbConfig)) { return ::GetLastError(); } COMMTIMEOUTS commTimeout; if (GetCommTimeouts(h, &commTimeout)) /* Configuring Read & Write Time Outs */ { commTimeout.ReadIntervalTimeout = 1000 * dwTimeOutInSec; commTimeout.ReadTotalTimeoutConstant = 1000 * dwTimeOutInSec; commTimeout.ReadTotalTimeoutMultiplier = 0; commTimeout.WriteTotalTimeoutConstant = 1000 * dwTimeOutInSec; commTimeout.WriteTotalTimeoutMultiplier = 0; } else { return ::GetLastError(); } if (SetCommTimeouts(h, &commTimeout)) { return ERROR_SUCCESS; } else { return ::GetLastError(); }}
开发者ID:swartzb,项目名称:rs232,代码行数:52,
示例23: term_set_control/* device control settings */unsigned int term_set_control ( unsigned int baud, unsigned char databits, unsigned char stopbits, unsigned char parity, unsigned char handshake ){ /* todo: - error checking - handshake - parity - stopbits - let the user configure timeouts ? */ COMMCONFIG lpCC; COMMTIMEOUTS timeouts; if ( !hCom ) { printf ( "%s: COM port was not open!/n", __FUNCTION__ ); return RXE_FAIL; } GetCommTimeouts ( hCom, &timeouts ); // TODO timeouts.ReadIntervalTimeout = 1; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.ReadTotalTimeoutConstant = 10; timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 10; if ( !SetCommTimeouts ( hCom, &timeouts ) ) { printf ( "%s: setting timeouts didn't work!/n", __FUNCTION__ ); return RXE_FAIL; } GetCommState ( hCom, &lpCC.dcb ); lpCC.dcb.BaudRate = baud ? baud: CBR_115200; lpCC.dcb.ByteSize = databits; lpCC.dcb.StopBits = ONESTOPBIT; lpCC.dcb.Parity = NOPARITY; lpCC.dcb.fDtrControl = DTR_CONTROL_DISABLE; lpCC.dcb.fRtsControl = RTS_CONTROL_DISABLE; SetCommState ( hCom, &lpCC.dcb ); return RXE_OK;}
开发者ID:kalakal06,项目名称:badadroid,代码行数:51,
示例24: GetCommTimeouts// Set Rx Timeout in ms// Timeout: Rx receive timeout in ms// return: last set Rx timeout or -1 on errorint ComPort::SetRxTimeout(int Timeout){ COMMTIMEOUTS CommTimeouts; int result; DWORD dwError; if (hPort == INVALID_HANDLE_VALUE) return -1; GetCommTimeouts(hPort, &CommTimeouts); result = CommTimeouts.ReadTotalTimeoutConstant; // Change the COMMTIMEOUTS structure settings. CommTimeouts.ReadIntervalTimeout = MAXDWORD; // JMW 20070515 if (Timeout == 0) { // no total timeouts used CommTimeouts.ReadTotalTimeoutMultiplier = 0; CommTimeouts.ReadTotalTimeoutConstant = 0; } else { // only total timeout used CommTimeouts.ReadTotalTimeoutMultiplier = MAXDWORD; CommTimeouts.ReadTotalTimeoutConstant = Timeout; } CommTimeouts.WriteTotalTimeoutMultiplier = 10; CommTimeouts.WriteTotalTimeoutConstant = 1000; // Set the time-out parameters // for all read and write // operations on the port. if (!SetCommTimeouts(hPort, &CommTimeouts)) { // Could not create the read thread. CloseHandle(hPort); hPort = INVALID_HANDLE_VALUE;#if (WINDOWSPC>0) || NEWCOMM // 091206 Sleep(2000); // needed for windows bug#endif ComPort_StatusMessage(MB_OK, TEXT("Error"), TEXT("%s %s"), // LKTOKEN [email C++ GetCommand函数代码示例 C++ GetCommState函数代码示例
|