Cheetos
Member level 3
This is my code in my program. i am having problems because when i transmit '1', i receive a different character. sometimes it is even a special character. by the way my OS is LINUX, i am using USB to RS232 converter, Codeblocks with Libserial library, and Xbee modules. Please help
Code:
#include <iostream>
#include <fstream>
#include <SerialStream.h>
#include <cstdlib>
//#include <sys/types.h>
// #include <sys/stat.h>
// #include <fcntl.h>
using namespace std;
using namespace LibSerial;
main(){
double i;
char character;
SerialStream serialPort;
serialPort.Open("/dev/ttyUSB0");
serialPort.SetBaudRate( SerialStreamBuf::BAUD_9600) ;
serialPort.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
serialPort.SetNumOfStopBits(1) ;
serialPort.SetParity( SerialStreamBuf::PARITY_NONE ) ;
serialPort.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ;
if ( ! serialPort.good() )
{
std::cerr << "Error: Could not open serial port "
<< "/dev/ttyUSB0"
<< std::endl ;
exit(1) ;
}
while(i<20){
sleep(1);
serialPort<< '1' <<std::endl;
sleep(1);
//printf("i transmitted i think\n");
i++;
}
serialPort.Close();
return (0);
}
Last edited by a moderator: