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

C++ SerialStream类代码示例

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

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



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

示例1: Transmit

void Broadcast::Transmit()
{
    SerialStream mySerial;
    mySerial.Open("/dev/ttyUSB0");
    mySerial.SetBaudRate(SerialStreamBuf::BAUD_9600);
    mySerial << Data;
}
开发者ID:CountMurphy,项目名称:TempMon,代码行数:7,代码来源:Broadcast.cpp


示例2: ThreadFunc

DWORD WINAPI ThreadFunc(LPVOID lpParam)
{
    SerialStream stream;
    if (!stream.open(4))
    {
        std::cout << "Couldn't open COM" << std::endl;
        return -1;
    }

    string output;

    while (true)
    {
        stream >> output;

        int ind1, ind2, ind3;
        stringstream ss;
        ind1 = output.find("#");
        ind2 = output.find(",", ind1 + 1);
        ind3 = output.find("#", ind2+1);

        float desired, actual;
        ss << output.substr(ind1+1, ind2-ind1-1);
        ss >> desired;
        ss << output.substr(ind2 + 1, ind3 - ind2 - 1);
        ss >> actual;

        desiredData[desiredStart] = desired;
        actualData[actualStart] = actual;

        desiredStart = (desiredStart + 1) % 1000;
        actualStart = (actualStart + 1) % 1000;
    }
}
开发者ID:chriswald,项目名称:Radio,代码行数:34,代码来源:SerialGraph.cpp


示例3: main

int main(int argc, char** argv)
{

    /*The mySerialino must be setup to use the same baud rate*/
    cout << "opening port" << endl;
    mySerial.Open(PORT);
    mySerial.SetBaudRate(SerialStreamBuf::BAUD_9600);
    mySerial.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);
    cout << "port open" << endl;
    do
    {
        cout << "Press a command key, use q to quit: ";
        char val = cin.get();
        cout << "Key pressed was " << val << endl;
        cin.ignore();
        if (val == 'q') break;
        stringstream ss;
        string cmd;
        ss << val;
        ss >> cmd;
        cmd.append("#");
        sendSerial(cmd);
        
        if (val == 'b') 
        {
            cout << "value received = "  << getSerial() << endl;
        }            
     } while(1);   
}
开发者ID:9thSenseRobotics,项目名称:telo_ubuntu,代码行数:29,代码来源:serial_stream_works_well.cpp


示例4: 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


示例5: main

int main(int argc, char** argv)
{
    cout << "opening port" << endl;
    mySerial.Open(PORT);
    mySerial.SetBaudRate(SerialStreamBuf::BAUD_9600);
    mySerial.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);
    cout << "port open" << endl;
    
    ros::init(argc, argv, "serialCommands");
    ros::NodeHandle nh_;
    ros::Subscriber arduino_sub = nh_.subscribe("arduino_commands", 60, arduinoCallback);
    arduino_pub = nh_.advertise<std_msgs::String>("arduino_sensors", 5);
    ros::spin();
    mySerial.Close();
}
开发者ID:9thSenseRobotics,项目名称:telo_ubuntu,代码行数:15,代码来源:serial_stream_sink.cpp


示例6: readBlocking

// This function blocks for upto timeout usec and waits for data
// to be available on the port.
std::string readBlocking(SerialStream& serial_port, int timeout)
{
    while( serial_port.rdbuf()->in_avail() == 0 && timeout > 0 )
    {
        timeout -= 100;
        usleep(100);
    }
    if(timeout < 0)
        return std::string();
    return read(serial_port);
}
开发者ID:nicrip,项目名称:misc,代码行数:13,代码来源:pololu.cpp


示例7: main

int main(int argc, char **argv)
{
  // initialize global variables
  prevtime = std::chrono::system_clock::now();
  std::cerr << "koko1" << std::endl;
  for(int k=0;k<7;++k)
    data.push_back(0);
  
  ardu.Open(PORT);
  std::cerr << "koko2" << std::endl;
  ardu.SetBaudRate(SerialStreamBuf::BAUD_38400);
  ardu.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);
  std::cerr << "koko3" << std::endl;

  glutInit(&argc, argv);
  std::cerr << "koko4" << std::endl;
  InitGL();
  std::cerr << "koko5" << std::endl;
  glutMainLoop();

  return 0;
}
开发者ID:Hybryd,项目名称:HyIMUViewer,代码行数:22,代码来源:main.cpp


示例8: Serial_Open_Port

void Serial_Open_Port(string comPort)
{
        serial_port.Open( comPort ) ;
        if(! serial_port.good())
	{
		std::cerr<<"Error: could not open serial port"<<std::endl;
		exit(1);
	}
        serial_port.SetBaudRate( SerialStreamBuf::BAUD_9600) ;
        serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
        serial_port.SetNumOfStopBits(1) ;
        serial_port.SetParity( SerialStreamBuf::PARITY_EVEN ) ;
        serial_port.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ;
}
开发者ID:sojoe02,项目名称:RSD,代码行数:14,代码来源:serial_fct.cpp


示例9: serialport_open

void serialport_open(const char* sp) {
    /*The arduino must be setup to use the same baud rate*/
    fprintf(stdout, "Setting Params:\n");
    ardu.SetBaudRate( SerialStreamBuf::BAUD_115200 ) ;
    ardu.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
    ardu.SetNumOfStopBits(1) ;
    ardu.SetParity( SerialStreamBuf::PARITY_ODD ) ;
    ardu.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_HARD ) ;
    ardu.SetVTime(1);
    fprintf(stdout, "Opening:\n");
    ardu.Open( sp ) ;
    fprintf(stdout, "Opened:\n");

}
开发者ID:samzapo,项目名称:ServoController,代码行数:14,代码来源:ServoDriver.cpp


示例10: init_connection

void init_connection(SerialStream& stream)
{

	stream.Open("/dev/ttyUSB0");
	if (stream.IsOpen()){
		cout << "\tStream open" << endl;
	} else {
		cout << "\tCould not open stream" << endl;
		exit(1);
	}

	//Connection Characteristics
	stream.SetBaudRate(SerialStreamBuf::BAUD_9600);
	stream.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);
	stream.SetNumOfStopBits(1);
	stream.SetParity(SerialStreamBuf::PARITY_NONE);
	stream.SetFlowControl(SerialStreamBuf::FLOW_CONTROL_HARD); //??
	stream.SetVMin(1000);

}
开发者ID:cartejac,项目名称:AVR_motor_controlling,代码行数:20,代码来源:serial_int.cpp


示例11: main

int main(int argc,char** argv)
{
	char response[3];

	serial_stream.Open( argv[1] ) ;
	serial_stream.SetBaudRate( SerialStreamBuf::BAUD_115200 ) ;
	serial_stream.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
	serial_stream.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ;
	serial_stream.SetParity( SerialStreamBuf::PARITY_NONE ) ;
	serial_stream.SetNumOfStopBits(0) ;
	
	while (1)
	{
		serial_stream<<"ABCD";
		cout<<"waiting response"<<endl;
		serial_stream.read(response,3);
		cout<<response<<endl;
	}
	return 0;
}
开发者ID:thriller91,项目名称:Cansat-SupOp,代码行数:20,代码来源:comm1.cpp


示例12: open

void open()
{
	ardu.Open("/dev/ttyACM0");
	ardu.SetBaudRate(SerialStreamBuf::BAUD_9600);
	ardu.SetCharSize(SerialStreamBuf::CHAR_SIZE_8); 
}
开发者ID:jgillham,项目名称:AwesomeRobot,代码行数:6,代码来源:ardIO.cpp


示例13: write

void write(SerialStream& serial_port, const std::string& data)
{
    serial_port.write(data.c_str(), data.size());
}
开发者ID:nicrip,项目名称:misc,代码行数:4,代码来源:pololu.cpp


示例14: SerialComm

 SerialComm()
 {
     node.SetBaudRate(SerialStreamBuf::BAUD_9600);
     node.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);
     node.Open(PORT);
 }
开发者ID:QuinAsura,项目名称:LOCK,代码行数:6,代码来源:LOCK.cpp


示例15: serial_setup

void serial_setup( void ) 
{
    ardu.Open(PORT);
    ardu.SetBaudRate(BAUDRATE);
    ardu.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);
}
开发者ID:roofilin,项目名称:549-gusty,代码行数:6,代码来源:facedetect.cpp


示例16: open

void open(){
  /*The arduino must be setup to use the same baud rate*/ 
  ardu.Open(PORT);    
  ardu.SetBaudRate(SerialStreamBuf::BAUD_9600);  
}
开发者ID:maxywb,项目名称:botserverthing,代码行数:5,代码来源:serialtest.cpp


示例17: QObject

Server::Server(DomParser* _parser): QObject(0)
{
  parser = _parser;
  connect(&server, SIGNAL(newConnection()), this, SLOT(acceptConnection()));

  serial_port.Open(ARDUINO) ;
     if ( ! serial_port.good() )
     {
         std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] "
                   << "Error: Could not open serial port."
                   << std::endl ;
         exit(1) ;
     }
     //
     // Set the baud rate of the serial port.
     //
     serial_port.SetBaudRate( SerialStreamBuf::BAUD_9600 ) ;
     if ( ! serial_port.good() )
     {
         std::cerr << "Error: Could not set the baud rate." <<
std::endl ;
         exit(1) ;
     }
     //
     // Set the number of data bits.
     //
     serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
     if ( ! serial_port.good() )
     {
         std::cerr << "Error: Could not set the character size." <<
std::endl ;
         exit(1) ;
     }
     //
     // Disable parity.
     //
     serial_port.SetParity( SerialStreamBuf::PARITY_NONE ) ;
     if ( ! serial_port.good() )
     {
         std::cerr << "Error: Could not disable the parity." <<
std::endl ;
         exit(1) ;
     }
     //
     // Set the number of stop bits.
     //
     serial_port.SetNumOfStopBits( 1 ) ;
     if ( ! serial_port.good() )
     {
         std::cerr << "Error: Could not set the number of stop bits."
                   << std::endl ;
         exit(1) ;
     }
     //
     // Turn off hardware flow control.
     //
     serial_port.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ;
     if ( ! serial_port.good() )
     {
         std::cerr << "Error: Could not use hardware flow control."
                   << std::endl ;
         exit(1) ;
     }

  server.listen(QHostAddress::Any, 8888);
}
开发者ID:uUlmKnierim,项目名称:everywhereDisplaySoftware,代码行数:66,代码来源:server.cpp


示例18: main

int main()
{
    // Open the serial port for reading:
    ardu.Open(PORT);    
    ardu.SetBaudRate(SerialStreamBuf::BAUD_115200);  
    ardu.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);

    char str[8];
    // ardu << out;
    ardu >> str;
    std::cout << str;

    //sscanf(str,"%d",&res);


    //sleep(1);
    //serial_send(fd, 'A');
    sleep(1);
    //while(result != 'A')
    return 1;

    while(true)
    {
    ardu >> str;
    std::cout << str;
	//int test = read(fd, &byte, 1);
        //serial_send(fd, 'A');
        //printf("%i %i %c\n", test, byte, byte); 
        //sleep(1);
    }

    // Set the last signalled state of the system as sent by the opto signal over USB.
    // "t" is top-dead-center, and "b" is bottom-dead-center.
    char system_state = 'B';
    int image_counter = image_counter_min;    

    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");

    // Use v-sync (make it so that we sync with the monitor, and don't draw more than 60fps.
    App.UseVerticalSync(false);
    // App.SetFramerateLimit(60); // Limit to 60 frames per second
    // App.SetFramerateLimit(0);  // No limit

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // A key has been pressed
            if (Event.Type == sf::Event::KeyPressed)
            {
                // Escape key : exit
                if (Event.Key.Code == sf::Key::Escape)
                    App.Close();
            }
        }

        // Read from the USB port.
        uint8_t input_state; //= serial_recv(fd);
        printf("%i ", input_state);
        if (input_state != system_state && (input_state == 'B' || input_state == 'T'))
        {   // Start the appropriate image sequence.

            // Change the system state.
            system_state = input_state;
            //printf("%c\n", system_state);
            
            // Reset the image counter.
            image_counter = 0; 
        }

        // Get the elapsed time.
        float elapsed = Clock.GetElapsedTime();
        if (elapsed > refresh_rate)
        {
            // Update the image.
            printf("%i %f\n", image_counter, elapsed);
            Clock.Reset();

            // Increment or decrement the image counter.
            if (system_state == 'B') image_counter++;
            else if (system_state == 'T') image_counter++;
            
            // Make sure the counter doesn't go out of bounds.
            if (image_counter > image_counter_max) image_counter = image_counter_max;
            if (image_counter < image_counter_min) image_counter = image_counter_min;

            // Draw the appropriate colour:
            switch( image_counter ) 
            {
                case 0:
                    App.Clear(sf::Color(0, 0, 0));
                    break;
//.........这里部分代码省略.........
开发者ID:jamiej,项目名称:OpenVoxel,代码行数:101,代码来源:main.cpp


示例19: Serial_Close_Port

void Serial_Close_Port(void)
{
        if(serial_port.IsOpen())
	{
                serial_port.Close();
	}
}
开发者ID:sojoe02,项目名称:RSD,代码行数:7,代码来源:serial_fct.cpp


示例20: 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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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