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


C++ SerialStream::get方法代码示例

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


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

示例1: measureGravitation

void measureGravitation()
{
  double mean[3] = {0,0,0};
  int nbIter = 100;
  
  for(int k=0;k<nbIter;++k)
  {
    std::cerr << k << "/" << nbIter << "\r";
    // read data from IMU
    char c; // character
    std::string s("");
    ardu.get( c ) ;
    while(c != '#'){ardu.get( c );} // do nothing until we read the end of a block
    
    ardu.get( c );
    while(c != '#')
    {
      s += c;
      ardu.get( c );
    }
    splitData(s);
    
    mean[0] += data[4];
    mean[1] += data[5];
    mean[2] += data[6];
    
  }
  for(int j=0;j<3;++j)
    grav[j] = mean[j]/nbIter;
  
  std::cerr << std::endl;
}
开发者ID:Hybryd,项目名称:HyIMUViewer,代码行数:32,代码来源:main.cpp

示例2: DisplayCallback

void DisplayCallback(void)
{
  std::cerr << "sidpp" << std::endl;
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(zoom, aspect, zNear, zFar);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(0.0,0.0,-sdepth);
  glRotatef(-stheta, 1.0, 0.0, 0.0);
  glRotatef(sphi, 0.0, 0.0, 1.0);
  
  // read data from IMU
  
  char c; // character
  std::string s("");
  ardu.get( c ) ;
  while(c != '#'){ardu.get( c );} // do nothing until we read the end of a block
  
  ardu.get( c );
  while(c != '#')
  {
    s += c;
    ardu.get( c );
  }

  
  
  // Convert string to std::vector<double>
//  std::vector<double> data = splitData(s);
  splitData(s);

// for(int k=0;k<data.size();++k)
// std::cerr << data[k] << std::endl;
  
  
  // Move the cube
  UpdatePosition();
  
  // Orient the cube
  DrawFromQuaternion(data);
  
  


  glutSwapBuffers();
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
开发者ID:Hybryd,项目名称:HyIMUViewer,代码行数:48,代码来源:main.cpp

示例3: read

// This function returns queued data on port, returns empty string if there is no data
// does not block
string read(SerialStream& serial_port)
{
    string result;
    while( serial_port.rdbuf()->in_avail() )
    {
        char next_byte;
        serial_port.get(next_byte);
        result += next_byte;
    }
    return result;
}
开发者ID:nicrip,项目名称:misc,代码行数:13,代码来源:pololu.cpp

示例4: startRead

void Server::startRead()
{
      char buffer[1024] = {0};
      client->read(buffer, client->bytesAvailable());
      cout << buffer << endl;
      if(buffer[0] == 'l'){
           emit moving();
//           rot = rot + 5;
//           if(rot > 230)
//                   rot=0;
           serial_port <<"05"<<endl;
           //serial_port << ROT << "#" << rot << endl;
      }

      if(buffer[0] == 'r'){
          emit moving();
//          rot = rot - 5;
//                  if(rot < -30)
//                  rot = 210;
          serial_port <<"07"<<endl;
          //serial_port << ROT <<"#" << rot << endl;
      }

      if(buffer[0] == 'u'){
          emit moving();
//          tilt = tilt - 5;
          //TODO: overflow
          serial_port <<"04"<<endl;
          //serial_port << TILT <<"#" << tilt << endl;
      }

      if(buffer[0] == 'd'){
          emit moving();
//          tilt = tilt + 5;
          //TODO: Overflow
          serial_port <<"06"<<endl;
          //serial_port << TILT <<"#" << tilt << endl;
      }

      if(buffer[0] == 's'){
        std::string strBuffer(buffer);
        unsigned pos = strBuffer.find("#");
        std::string name = strBuffer.substr(pos+1);
        std::cout << "Name of surface: " << name << std::endl;
        //Send position request
        serial_port << "00" << endl;

        // Read Position response
        char temp=0;
        int i=0;
        char cstr[64];
        while(temp!='\n')
        {
            try
            {
                serial_port.get(temp);
               // temp=serial_port.ReadByte(100);
            }
            catch(SerialPort::ReadTimeout &e)
            {
                cout<<"Read Timeout"<<endl;
            }
            if((temp!='\n')&&(temp!=0)&&(temp!=' '))
            {
                cstr[i]=temp;
                ++i;
                //cout<<i++<<temp<<'x'<<endl;
            }
        }
        cstr[i]='\0';

        std::string dataBuffer(cstr);
        unsigned pos1 = dataBuffer.find("#");
        unsigned pos2 = dataBuffer.find("#",pos1+1);

        std::string rotString = dataBuffer.substr(pos1+1, pos2-pos1-1);
        std::string tiltString = dataBuffer.substr(pos2+1);

        std::cout <<"i got from " << dataBuffer << "\nrot: " << rotString << " and tilt: " << tiltString << std::endl;


        int rot =  QString::fromStdString(rotString).toFloat(NULL);
        int tilt =  QString::fromStdString(tiltString).toFloat(NULL);

        std::cout << "Rotation: " << rot << " Tilt: "<< tilt << std::endl;

        emit save(QString::fromStdString(name),rot,tilt);
      }

      if(buffer[0] == 'p'){
          //ToDo Distance
          char * lf ="\n" ;
          QStringList top = parser->surfaceNames();
          for ( QStringList::Iterator it = top.begin(); it != top.end(); ++it ) {
                 printf( "%s \n", (*it).toUtf8().constData() );
                 client->write((*it).toUtf8());
                 client->write(lf);
           }
          client->write(lf); // EoS
          client->flush(); //is, like always, important
//.........这里部分代码省略.........
开发者ID:uUlmKnierim,项目名称:everywhereDisplaySoftware,代码行数:101,代码来源:server.cpp


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