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

C++ TimeOut类代码示例

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

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



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

示例1: device

/*!
     \brief Read an array of bytes from the serial device (with timeout)
     \param Buffer : array of bytes read from the serial device
     \param MaxNbBytes : maximum allowed number of bytes read
     \param TimeOut_ms : delay of timeout before giving up the reading
     \return >=0 return the number of bytes read before timeout or
                requested data is completed
     \return -1 error while setting the Timeout
     \return -2 error while reading the byte
  */
int rOc_serial::readBytes (void *Buffer,unsigned int MaxNbBytes,unsigned int TimeOut_ms, unsigned int SleepDuration_us)
{
#if defined (_WIN32) || defined(_WIN64)
    DWORD dwBytesRead = 0;
    timeouts.ReadTotalTimeoutConstant=(DWORD)TimeOut_ms;                // Set the TimeOut
    if(!SetCommTimeouts(hSerial, &timeouts))                            // Write the parameters
        return -1;                                                      // Error while writting the parameters
    if(!ReadFile(hSerial,Buffer,(DWORD)MaxNbBytes,&dwBytesRead, NULL))  // Read the bytes from the serial device
        return -2;                                                      // Error while reading the byte
    return dwBytesRead;
#endif
#ifdef __linux__
    TimeOut          Timer;                                             // Timer used for timeout
    Timer.InitTimer();                                                  // Initialise the timer
    unsigned int     NbByteRead=0;
    while (Timer.ElapsedTime_ms()<TimeOut_ms || TimeOut_ms==0)          // While Timeout is not reached
    {
        unsigned char* Ptr=(unsigned char*)Buffer+NbByteRead;           // Compute the position of the current byte
        int Ret=read(fd,(void*)Ptr,MaxNbBytes-NbByteRead);              // Try to read a byte on the device
        if (Ret==-1) return -2;                                         // Error while reading

        // One or several byte(s) has been read on the device
        if (Ret>0)
        {
            NbByteRead+=Ret;                                            // Increase the number of read bytes
            if (NbByteRead>=MaxNbBytes)                                 // Success : bytes has been read
                return NbByteRead;
        }
        // Suspend the loop to avoid charging the CPU
        usleep (SleepDuration_us);
    }
    return NbByteRead;                                                  // Timeout reached, return the number of bytes read
#endif
}
开发者ID:bithollow,项目名称:BH,代码行数:44,代码来源:rOc_serial.cpp


示例2: disable

/*!
     \brief Wait for a byte from the serial device and return the data read
     \param pByte : data read on the serial device
     \param TimeOut_ms : delay of timeout before giving up the reading
            If set to zero, timeout is disable (Optional)
     \return 1 success
     \return 0 Timeout reached
     \return -1 error while setting the Timeout
     \return -2 error while reading the byte
  */
char rOc_serial::readChar(char *pByte,unsigned int TimeOut_ms)
{
#if defined (_WIN32) || defined(_WIN64)

    DWORD dwBytesRead = 0;
    timeouts.ReadTotalTimeoutConstant=TimeOut_ms;                       // Set the TimeOut
    if(!SetCommTimeouts(hSerial, &timeouts))                            // Write the parameters
        return -1;                                                      // Error while writting the parameters
    if(!ReadFile(hSerial,pByte, 1, &dwBytesRead, NULL))                 // Read the byte
        return -2;                                                      // Error while reading the byte
    if (dwBytesRead==0) return 0;                                       // Return 1 if the timeout is reached
    return 1;                                                           // Success
#endif
#ifdef __linux__
    TimeOut         Timer;                                              // Timer used for timeout
    Timer.InitTimer();                                                  // Initialise the timer
    while (Timer.ElapsedTime_ms()<TimeOut_ms || TimeOut_ms==0)          // While Timeout is not reached
    {
        switch (read(fd,pByte,1)) {                                     // Try to read a byte on the device
        case 1  : return 1;                                             // Read successfull
        case -1 : return -2;                                            // Error while reading
        }
    }
    return 0;
#endif
}
开发者ID:bithollow,项目名称:BH,代码行数:36,代码来源:rOc_serial.cpp


示例3: disable

/*!
     \brief Wait for a byte from the serial device and return the data read
     \param pByte : data read on the serial device
     \param TimeOut_ms : delay of timeout before giving up the reading
            If set to zero, timeout is disable (Optional)
     \return 1 success
     \return 0 Timeout reached
     \return -1 error while setting the Timeout
     \return -2 error while reading the byte
  */
char Serial::ReadChar(char *pByte,int TimeOut_ms)
{
    TimeOut         Timer;                                              // Timer used for timeout
    Timer.InitTimer();                                                  // Initialise the timer
    while (Timer.ElapsedTime_ms()<TimeOut_ms || TimeOut_ms==0)          // While Timeout is not reached
    {
        switch (read(fd,pByte,1)) {                                     // Try to read a byte on the device
        case 1  : return 1;                                             // Read successfull
        case -1 : return -2;                                            // Error while reading
        }
    }
    return 0;
}
开发者ID:codelectron,项目名称:Krixoid,代码行数:23,代码来源:Serial.cpp


示例4: device

/*!
     \brief Read an array of bytes from the serial device (with timeout)
     \param Buffer : array of bytes read from the serial device
     \param MaxNbBytes : maximum allowed number of bytes read
     \param TimeOut_ms : delay of timeout before giving up the reading
     \return 1 success, return the number of bytes read
     \return 0 Timeout reached
     \return -1 error while setting the Timeout
     \return -2 error while reading the byte
  */
int Serial::Read (void *Buffer,unsigned int MaxNbBytes,unsigned int TimeOut_ms)
{
    TimeOut          Timer;                                             // Timer used for timeout
    Timer.InitTimer();                                                  // Initialise the timer
    unsigned int     NbByteRead=0;
    while (Timer.ElapsedTime_ms()<TimeOut_ms || TimeOut_ms==0)          // While Timeout is not reached
    {
        unsigned char* Ptr=(unsigned char*)Buffer+NbByteRead;           // Compute the position of the current byte
        int Ret=read(fd,(void*)Ptr,MaxNbBytes-NbByteRead);              // Try to read a byte on the device
        if (Ret==-1) return -2;                                         // Error while reading
        if (Ret>0) {                                                    // One or several byte(s) has been read on the device
            NbByteRead+=Ret;                                            // Increase the number of read bytes
            if (NbByteRead>=MaxNbBytes)                                 // Success : bytes has been read
                return 1;
        }
    }
    return 0;                                                           // Timeout reached, return 0
}
开发者ID:codelectron,项目名称:Krixoid,代码行数:28,代码来源:Serial.cpp


示例5: perform_test_trivial

 void perform_test_trivial() {
   TimeOut s;
   typedef ParserResultElement<TimeOut> Parser;
   Parser p(s);
   {
     typedef std::vector<std::string> Vector;
     Vector test_vector;
     test_vector.push_back("0");
     test_vector.push_back("1");
     test_vector.push_back("1200");
     for (Vector::const_iterator i = test_vector.begin(); i != test_vector.end(); ++i) {
       const std::string test = *i;
       typedef typename TimeOut::natural_number_type natural_number_type;
       const natural_number_type time_out = boost::lexical_cast<natural_number_type>(test);
       OKLIB_TESTTRIVIAL_RETHROW(::OKlib::Parser::Test_ParsingString<Parser>(p, test, ::OKlib::Parser::match_full));
       if(s.time_out() != time_out)
         OKLIB_THROW("Time_Out is " + boost::lexical_cast<std::string>(s.time_out()) + ", and not " + boost::lexical_cast<std::string>(time_out));
     }
   }
 }
开发者ID:MLewsey,项目名称:oklibrary,代码行数:20,代码来源:ParsingSingleResult_Tests.hpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ TimePoint类代码示例发布时间:2022-05-31
下一篇:
C++ TimeManager类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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