#include #include #include #include int mrfd = -1; int mropen(char *device) { struct termio mrtio; if (mrfd >= 0) return mrfd; if ((mrfd=open(device,O_RDWR | O_NDELAY, 0x666)) < 0) return -1; if (ioctl(mrfd,TCGETA,(char *)&mrtio) == -1) return -1; mrtio.c_iflag = (BRKINT | IGNPAR); mrtio.c_oflag = 0; mrtio.c_lflag = 0; mrtio.c_cflag = (B9600 | CS8 | CLOCAL | CREAD); mrtio.c_cc[VMIN] = 0; mrtio.c_cc[VTIME] = 1; if ((ioctl(mrfd,TCSETA,(char *)&mrtio)) == -1) return -1; return mrfd; } int mrclose() { if (mrfd < 0) return -1; close(mrfd); mrfd = -1; } float mrpos(int point) { char bufout[15], bufin[25]; double pos; int i, iread, iwrite; long start_usec, delta_usec; struct timeval tval; struct timezone tzone; sprintf(bufout," 0) i += iread; if (bufin[i-1] == '\r' && i) { sscanf(bufin,"%lf",&pos); return pos; break; } gettimeofday(&tval, &tzone); delta_usec = tval.tv_usec - start_usec; if (delta_usec < 0) delta_usec += 1000000L; } while (delta_usec < 750000L); /* while((iread=read(mrfd,&bufin[i],20)) > 0) { i += iread; } if (i) { sscanf(bufin,"%lf",&pos); } else { pos = 999.99999; } */ pos = 999.99999; return pos; }