<<attachment: phase3.gif>>
/***************************************************************************
rdxp.c
Read phase and freq from Racal-Dana 1992
-------------------
***************************************************************************/
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <getopt.h>
#include <sys/time.h>
#include "gpib/ib.h"
#define LL 132
char line[LL];
long double phase, freq;
struct timeval tv;
long long tt;
FILE *fout;
int ud, minor=0, pad = 15;
const int sad = 0;
const int send_eoi = 1;
const int eos_mode = 0;
const int timeout = T1s;
int once = 1; // discard garbage readings forst time around
main(argc, argv)
{
long long l;
fout = fopen("/o/tmp/rdxp", "w");
if (fout == NULL)
fprintf(stderr, "Can't open output file.\n");
fprintf(stderr, "trying to open pad = %i on /dev/gpib%i ... ", pad,
minor);
ud = ibdev(minor, pad, sad, timeout, send_eoi, eos_mode);
if(ud < 0)
{
fprintf(stderr, "ibdev error\n");
return (-1);
}
fprintf(stderr, "ud = %d\n", ud);
ibrsc(ud, 1);
ibsic(ud);
ibclr(ud);
ibsre(ud, 1);
ibwrt(ud, "SRS9\n", 5); // set high res
once = 1;
while (1) {
ibwrt(ud, "PH\n", 3); // measure phase
line[0] = 0;
Receive (0, 15, line, LL, 012);
if (strncmp(line, "PH", 2)) {
fprintf(stderr, "PH Timeout\n"); continue;
}
// fputs (line, stdout);
sscanf (line+2, "%Le", &phase);
ibwrt(ud, "FA\n", 3); // Measure freq input A
line[0] = 0;
Receive (0, 15, line, LL, 012);
if (strncmp(line, "FA", 2)) {
fprintf(stderr, "FA Timeout\n"); continue;
}
// fputs (line, stdout);
gettimeofday(&tv, NULL); tt = tv.tv_sec;
sscanf (line+2, "%Le", &freq);
/*
* Display freq as deviation from the nearest MHz
*/
l = freq + 50000.;
l /= 100000;
l *= 100000;
freq -= l;
if (once) {once = 0; continue;}
fprintf(stdout, "%lld %12.2Lf %3.0Lf\n", tt, freq, phase );
fflush(stdout);
if (fout != NULL) {
fprintf(fout,"%lld %12.2Lf %3.0Lf\n", tt, freq, phase );
fflush(fout);
}
}
}
_______________________________________________ time-nuts mailing list -- [email protected] To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts and follow the instructions there.
