Esempio n. 1
0
int main()
{
    LibSerial::SerialStream ss;
    ss.Open("/dev/ttyACM0"); //serial/by-id/usb-LeafLabs_Maple-if00");

    if ( !ss.good() )
    {
        std::cout << "Not good" << std::endl;
        exit(1);
    }

    ss.SetCharSize( LibSerial::SerialStreamBuf::CHAR_SIZE_8 ) ;
    if ( !ss.good() )
    {
        std::cout << "can't set char size" << std::endl;
        exit(1);
    }

    char c = 0x1;

    write_letter(ss,l_a);

    usleep(1000000);

    write_letter(ss,l_b);

    //ss.write(&c, 0);
}
int setup_serial_port(  LibSerial::SerialStream& serial_port, 
						const char* SERIAL_PORT_DEVICE,
						LibSerial::SerialStreamBuf::BaudRateEnum baud_rate
						) {
	
	using namespace LibSerial;    
	
	//Open the port SERIAL_PORT_DEVICE
	serial_port.Open( SERIAL_PORT_DEVICE );
	if ( ! serial_port.good() ) {
		std::cout << "Not able to open serial port at " << SERIAL_PORT_DEVICE << std::endl;
		return 0;
	}
	//Set Baudrate
	serial_port.SetBaudRate( baud_rate );
	if ( ! serial_port.good() ) {
		std::cout << "Unable to set Baud Rate " << std::endl;
		return 0;
	}

	//Set Character Size
	serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 );
	if( ! serial_port.good() ) {
		std::cout << "Unable to set Char Size 8" << std::endl;
		return 0;
	}

	//Set Parity
	serial_port.SetParity( SerialStreamBuf::PARITY_NONE );

	if( ! serial_port.good() ) {
		std::cout << "Unable to set Parity None " << std::endl;
		return 0;
	}

	//Set Number of Stop Bits
	serial_port.SetNumOfStopBits( 1 );
	if( ! serial_port.good() ) {
		std::cout << "Unable to set Num of Stop Bits 1 " << std::endl;
		return 0;
	}

	//Set Hardware Flow Control 
	serial_port.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE );
	if( ! serial_port.good() ) {
		std::cout << "Unable to set Hardware Flow Control None" << std::endl;
		return 0;
	}

	return 1;
}