Hi!

I'm trying to import readings from my GPS using c++ code, but have som difficulty. I have used the tutorial given at http://www.easysw.com/~mike/serial/serial.html, but it doesn't work.

I sometimes am able to receive some measurements, but then it can freeze the next time i run it. The program then freezes at read().

Further, the HW is all ok, as i get readings using cutecom. with the same settings.

int open_port(){
fd = open("/dev/ttyUSB1", O_RDWR | O_NOCTTY);
if (fd == -1){
//Couldn't open port
perror("Open_port: Unable to open device");
cout << "Try running the config file again\n";
return -1;
}
fcntl(fd, F_SETFL, 0);

struct termios options;

// Loading current options
if (tcgetattr(fd, &options)){
perror("Could not load options ");
return -2;
}

// Setting 4800 baud rate
cfsetispeed(&options, B4800);
cfsetospeed(&options, B4800);

options.c_cflag |= (CLOCAL | CREAD); // Enabling reciever, setting local mode

options.c_cflag &= ~CSIZE; // Mask the character size bits
options.c_cflag |= CS8; // Select 8 data bits

options.c_cflag &= ~(PARENB | PARODD);
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CRTSCTS;
options.c_lflag |= (ICANON | ECHO | ECHOE);
options.c_iflag |= (INPCK | ISTRIP);
options.c_iflag &= ~(IXON | IXOFF | IXANY);

tcsetattr(fd, TCSANOW, &options);
char m_buf[4096];
int bytesRead=read(fd, m_buf, 4096);

return 1;
}

Any help would be appreciated.