#ifdef HAVE_LABJACK #include "libsurf.h" #include "ljackv112.h" #endif #include #include #include #include #define NSAMP 10 #define STRLEN 100 static void usage () { fprintf(stderr, "dac: usage: dac -c chn -b board\n"); exit(1); } int main (int argc, char **argv) { #ifdef HAVE_LABJACK int i; int chn = -1; char c; long id = 0; long ov; char bname[STRLEN] = { 0 }; float v; while ((c = getopt(argc, argv, "c:b:")) != -1) { switch (c) { case 'c': chn = atoi(optarg); break; case ':': strncpy(bname, optarg, STRLEN - 1); bname[STRLEN - 1] = 0; break; default: strncpy(bname, optarg, STRLEN - 1); bname[STRLEN - 1] = 0; break; case '?': usage(); } } if (strlen(bname) == 0 || chn < 0) usage(); fprintf(stderr, "Calibrating board %s, chn %d\n", bname, chn); if (surf_brd_ena(bname, chn, 1) < 0) return 2; if (surf_brd_end(bname, chn, 1) < 0) return 2; for (i = 0; i < 0x100; ++i) { int j; float sum_a = 0, sum_d = 0; if (surf_brd_set_anl_dac(bname, chn, i) < 0) return 2; if (surf_brd_set_dig_dac(bname, chn, i) < 0) return 2; /* the first step usually involves lots of ramping. */ if (!i) sleep(2); printf("RDAC %3d:", i); fflush(stdout); /* allow some time to settle */ usleep((unsigned long)1e5); for (j = 0; j < NSAMP; ++j) { if (EAnalogIn(&id, 0, 4, 0, &ov, &v)) return 3; sum_d += v; if (EAnalogIn(&id, 0, 5, 0, &ov, &v)) return 3; sum_a += v; /* printf(" %.3f", v); */ /* fflush(stdout); */ } printf(" %.3f (dig)\t %.3f (anl)\n", sum_d / (double)NSAMP, sum_a / (double)NSAMP); fflush(stdout); } if (surf_brd_ena(bname, chn, 0) < 0) return 2; if (surf_brd_end(bname, chn, 0) < 0) return 2; #endif return 0; }