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);   
}
Ejemplo n.º 2
0
void Broadcast::Transmit()
{
    SerialStream mySerial;
    mySerial.Open("/dev/ttyUSB0");
    mySerial.SetBaudRate(SerialStreamBuf::BAUD_9600);
    mySerial << Data;
}
Ejemplo n.º 3
0
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");

}
Ejemplo n.º 4
0
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 ) ;
}
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();
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
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);

}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
void open()
{
	ardu.Open("/dev/ttyACM0");
	ardu.SetBaudRate(SerialStreamBuf::BAUD_9600);
	ardu.SetCharSize(SerialStreamBuf::CHAR_SIZE_8); 
}
Ejemplo n.º 10
0
void open(){
  /*The arduino must be setup to use the same baud rate*/ 
  ardu.Open(PORT);    
  ardu.SetBaudRate(SerialStreamBuf::BAUD_9600);  
}
Ejemplo n.º 11
0
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;
                case 1:
                    App.Clear(sf::Color(85, 85, 85));
                    break;
                case 2:
                    App.Clear(sf::Color(170, 170, 170));
                    break;
                case 3:
                    App.Clear(sf::Color(255, 255, 255));
                    break;
            }

        }

        // Clear the screen with red color
        // App.Clear(sf::Color(200, 0, 0));

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}
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);
}
Ejemplo n.º 13
0
void serial_setup( void ) 
{
    ardu.Open(PORT);
    ardu.SetBaudRate(BAUDRATE);
    ardu.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);
}
Ejemplo n.º 14
0
 SerialComm()
 {
     node.SetBaudRate(SerialStreamBuf::BAUD_9600);
     node.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);
     node.Open(PORT);
 }