Tuota timeouttia olen kasvatellut eri tavoin.
Tässä on tuon C-kielisen osan sorsat
#define TERMINAL "/dev/ttyS2"
#define FALSE 0
#define TRUE !(FALSE)
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
/**********************/
int set_interface_attribs(int fd, int speed){
struct termios tty;
if (tcgetattr(fd, &tty) < 0) {
printf("Error from tcgetattr: %s\n", strerror(errno));
return -1;
}
cfsetospeed(&tty, (speed_t)speed);
cfsetispeed(&tty, (speed_t)speed);
tty.c_cflag |= (CLOCAL | CREAD); /* ignore modem controls */
tty.c_cflag &= ~CSIZE;
tty.c_cflag |= CS8; /* 8-bit characters */
tty.c_cflag &= ~PARENB; /* no parity bit */
tty.c_cflag &= ~CSTOPB; /* only need 1 stop bit */
tty.c_cflag &= ~CRTSCTS; /* no hardware flowcontrol */
/* setup for non-canonical mode */
tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
tty.c_lflag &= ~(ECHO | ECHONL | ISIG | IEXTEN);
tty.c_oflag &= ~OPOST;
/* fetch bytes as they become available */
tty.c_cc[VMIN] = 50;
tty.c_cc[VTIME] = 3;
if (tcsetattr(fd, TCSANOW, &tty) != 0) {
printf("Error from tcsetattr: %s\n", strerror(errno));
return -1;
}
return 0;
}
int main(){
char *port = TERMINAL;
int fd;
unsigned char c;
unsigned char line[120];
unsigned char temp[120];
unsigned char jatkuu=1;
unsigned int len;
fd=open("/dev/ttyS2",O_RDONLY);
if (fd < 0) {
printf("Error opening %s: %s\n", port, strerror(errno));
return -1;
}
/*baudrate 9600, 8 bits, no parity, 1 stop bit */
set_interface_attribs(fd, B9600);
do {
len = read(fd, &line, sizeof(line));
if(strncmp("$GPRMC",line,5)==0){
jatkuu=0;
// Leikataan alusta 7 merkkiä ja lopusta 8 merkkiä:
memmove(temp, line + 7, len -7-5 + 1);
printf("LEN=%d %s\n",len,temp);
}
} while (jatkuu);
close(fd);
}