c++ - termios Arduino read/write failing -


hello having trouble trying program arduino take commands c++ program. using termios connect arduino. arduino in gateway mode (basically not executing code waiting input program interact hardware connect it).

my termios set this:

serialhandler::serialhandler(char* fpath, int brate) { filepath = fpath; baudrate = 0;  //open file, file of type int file = open(filepath, o_rdwr | o_noctty); if(file<0) //if there error opening file {     perror(filepath);     exit(-1); } //save old port settings tcgetattr(file, &oldtio); bzero(&newtio, sizeof(newtio)); //now load baudrate getbaudrate(brate, baudrate); newtio.c_cflag = baudrate | crtscts | cs8 | clocal | cread;  //ignpar ignore bits parity errors //icrnl  map cr nl ..may have change raw input processing newtio.c_iflag = ignpar;  //raw output newtio.c_oflag = 0;  //icanon - enable canonical input //disables echo functionality, doesnt send signals calling program newtio.c_lflag = icanon;  //clean , activate port tcflush(file, tciflush); tcsetattr(file, tcsanow, &newtio); } 

and code write , read arduino this:

void serialhandler::getserialoutput(char* readbuffer, int& bufferpoint) { cout <<"beginning read\n";   bufferpointer = read(file, outputbuffer,255); cout <<"finished read\n"; for(int i=0;i<bufferpointer;i++) {     cout << outputbuffer[i]<<endl;     readbuffer[i] = outputbuffer[i]; } bufferpoint = bufferpointer; }   void serialhandler::writeserial(char* writebuffer, int length) { cout << "writing: " << writebuffer<<endl; write(file,writebuffer,length); cout << "finished write \n"; } 

initially send arduino test command ("at\r\n") , responds ("ok") after subsequent read/writes fail.

on test command arduino's rx , tx pins light (meaning recieving , transmitting data) , commands send after fail. arduino not light when try write , read commands hang indefinitely.

i think problem file handler closing unsure of how test or problem altogether.

try remove crtscts newtio.c_cflag line. crtscts needed when connect cables of serial connection. when using arduino connect tx rx , gnd lines. see termios man page more information http://linux.die.net/man/3/termios


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -