00001 #include <iostream>
00002 #include <SerialStream.h>
00003 #include <cstdlib>
00004
00005 int
00006 main( int argc,
00007 char** argv )
00008 {
00009
00010
00011
00012 using namespace LibSerial ;
00013 SerialStream serial_port ;
00014 serial_port.Open( "/dev/ttyUSB1" ) ;
00015 if ( ! serial_port.good() )
00016 {
00017 std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] "
00018 << "Error: Could not open serial port."
00019 << std::endl;
00020 exit(1) ;
00021 }
00022
00023
00024
00025 serial_port.SetBaudRate( SerialStreamBuf::BAUD_115200 ) ;
00026 if ( ! serial_port.good() )
00027 {
00028 std::cerr << "Error: Could not set the baud rate." << std::endl ;
00029 exit(1) ;
00030 }
00031
00032
00033
00034 serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
00035 if ( ! serial_port.good() )
00036 {
00037 std::cerr << "Error: Could not set the character size." << std::endl ;
00038 exit(1) ;
00039 }
00040
00041
00042
00043 serial_port.SetParity( SerialStreamBuf::PARITY_NONE ) ;
00044 if ( ! serial_port.good() )
00045 {
00046 std::cerr << "Error: Could not disable the parity." << std::endl ;
00047 exit(1) ;
00048 }
00049
00050
00051
00052 serial_port.SetNumOfStopBits( 1 ) ;
00053 if ( ! serial_port.good() )
00054 {
00055 std::cerr << "Error: Could not set the number of stop bits."
00056 << std::endl ;
00057 exit(1) ;
00058 }
00059
00060
00061
00062 serial_port.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ;
00063 if ( ! serial_port.good() )
00064 {
00065 std::cerr << "Error: Could not use hardware flow control."
00066 << std::endl ;
00067 exit(1) ;
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077 char c = '9';
00078 serial_port.write(&c,1);
00079 while (1)
00080 {
00081 char next_byte;
00082 serial_port.get(next_byte);
00083 std::cerr << std::hex << (int)next_byte << " ";
00084 usleep(15000);
00085 }
00086 std::cout << "finished" << std::endl;
00087 std::cerr << std::endl ;
00088 return EXIT_SUCCESS ;
00089 }