I've written a few quickies to pull data from my 1992.
Most run for as long as I care to run them.  The one I'm attaching
invariably flummoxes the counter after several hours.
It does a frequency measurement, then a phase measurement,
stores it, and repeats about once per second, dominated by the
time taken to measure the frequency.

It runs under Linux with the Linux GPIB package.  I am using
32 bit Fedora 16.

--
Chuck Forsberg WA7KGX N2469R     [email protected]   www.omen.com
Developer of Industrial ZMODEM(Tm) for Embedded Applications
  Omen Technology Inc      "The High Reliability Software"
10255 NW Old Cornelius Pass Portland OR 97231   503-614-0430

CFLAGS = -O -lgpib 

PROGS = rd10 rd1 rd2 rd5 rd6 rd rdp rdphase  rdx rdxp ibtest td td4 tdk tp

all:$(PROGS)

tgz:clean
        cd ..; tar cvfz /tmp/gpibwa7kgx.tgz rd

rd10:rd10.c
        cc rd10.c $(CFLAGS)  -o rd10
rd1:rd1.c
        cc rd1.c $(CFLAGS)  -o rd1
rd2:rd2.c
        cc rd2.c $(CFLAGS)  -o rd2
rd5:rd5.c
        cc rd5.c $(CFLAGS)  -o rd5
rd6:rd6.c
        cc rd6.c $(CFLAGS)  -o rd6
rd:rd.c
        cc rd.c $(CFLAGS)  -o rd
rdx:rdx.c
        cc rdx.c $(CFLAGS)  -o rdx
rdphase:rdphase.c
        cc rdphase.c $(CFLAGS)  -o rdphase
rdp:rdxp.c
        cc rdxp.c $(CFLAGS) -DPHASEONLY  -o rdp
rdxp:rdxp.c
        cc rdxp.c $(CFLAGS)  -o rdxp
ibtest:ibtest.c
        cc ibtest.c $(CFLAGS)  -o ibtest
td:td.c iplot.c
        cc td.c iplot.c  $(CFLAGS)  -lgpib -o td
td4:td4.c iplot.c
        cc td4.c iplot.c $(CFLAGS)  -o td4
tdk:tdk.c
        cc tdk.c $(CFLAGS)  -o tdk
tp:tp.c
        cc tp.c $(CFLAGS)  -lgpib -o tp

install:$(PROGS)
        cp -fp $(PROGS) ~/bin
clean:
        rm -f $(PROGS) a.out foo
cpq:
        cpq 0R* *.h *.c
/***************************************************************************
                                 rdxp.c
		Read phase and freq from Racal-Dana 1992
                             -------------------
		usage: rdxp [x]
			second arg selects 10 second gate time (default 1)
		usage: rdp

 ***************************************************************************/

#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 <signal.h>
#include <sys/time.h>
#include "gpib/ib.h"

#define LL 132
char line[LL];
long double  phase, freq;
long double  phase2 = -10;
long double  phase3 = 410;
struct timeval tv;
long long tt, ott, tt0;
FILE *fout;
struct timespec ts, tr;

int ud, minor=0, pad = 15;
const int sad = 0;
const int send_eoi = 1;
const int eos_mode = 0;
int timeout = T10s;
int res10 = 0;
long rcount = -1;
long count = 0;
int termflag = 0;	// recrived term signal, make a spike
int termcount = 0;

void
onintr(n)
{
#ifdef PHASEONLY
	fprintf(stderr, "\n\nRdp completed %ld loops, %d kills %ld resets.\n", count, termcount, rcount);
#else
	fprintf(stderr, "\n\nRdxp completed %ld loops, %ld resets.\n", count, rcount);
#endif
	exit (-1);
}

void
onintrterm(n)
{
	termflag = 1;
	signal(SIGTERM, onintrterm);
	++termcount;
	return;
}

main(argc, argv)
char *argv[];
{
	int  status;   long long l;

	signal(SIGINT, onintr);
	signal(SIGQUIT, onintr);
	signal(SIGTERM, onintrterm);

	res10 = (argc > 1);
	if (res10)
		timeout = T30s;
	ts.tv_nsec = 10e7;

#ifdef PHASEONLY
	fout = fopen("/o/tmp/rdp", "w");
#else
	fout = fopen("/o/tmp/rdxp", "w");
#endif
	if (fout  == NULL) {
		fprintf(stderr, "Can't open output file.\n");
		return (-1);
	}

	fprintf(stderr, "trying to open device %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);

oops:
	++rcount;
	ibrsc(ud, 1);
	ibsic(ud);
	ibclr(ud);
	ibeos(ud, REOS | 012);

#ifndef PHASEONLY
	if (res10) {
		ibwrt(ud, "SRS10\n", 6);		// set highest res
		timeout = T30s;
	} else
		ibwrt(ud, "SRS9\n", 5);		// set high res

	ibwrt(ud, "T1\n", 3);	// One-shot mode
	status = ibrd( ud, line, LL );		// discard possible spurious reading
#else
	ibwrt(ud, "PH\n", 3);	// measure phase
#endif
	while (1) {
		
#ifndef PHASEONLY
		ibwrt(ud, "PH\n", 3);	// measure phase
		nanosleep(&ts,  &tr);
		ibwrt(ud, "T2\n", 3);	// Take one reading
#endif
		status = ibrd( ud, line, LL );
		if( status & ERR )
		{
			fprintf(stderr, "PH Timeout %ld resets\n", rcount);
			goto oops;
		}
		sscanf (line+2, "%Le", &phase);
	
		
		gettimeofday(&tv, NULL); tt = tv.tv_sec;
		if (tt0 == 0)
			tt0 = tt;
#ifndef PHASEONLY
		ibwrt(ud, "FA\n", 3);	// Measure freq input A
		ibtmo(ud, timeout);
		ibwrt(ud, "T2\n", 3);	// Take one reading
		nanosleep(&ts,  &tr);
		status = ibrd( ud, line, LL );
		if( status & ERR )
		{
			fprintf(stderr, "FA Timeout %ld resets\n", rcount);
			goto oops;
		}
		sscanf (line+2, "%Le", &freq);
/*
 * Display freq as deviation from the nearest MHz
 */
		l = freq + 50000.;
		l /= 100000;
		l *= 100000;
		freq -= l;
		if (res10)
			fprintf(stdout, "%lld %12.3Lf %3.0Lf\n", tt, freq, phase );
		else
			fprintf(stdout, "%lld %12.2Lf %3.0Lf\n", tt, freq, phase );
		fflush(stdout);
		if (tt != ott && fout != NULL) {
			ott = tt;
			if (termflag) {
				fprintf(fout,"%lld %12.3Lf %3.0Lf %lld\n", tt-tt0, freq, phase2, tt );
				fprintf(fout,"%lld %12.3Lf %3.0Lf %lld\n", tt-tt0, freq, phase3, tt );
				termflag = 0;
				fprintf(stdout, " ****");
			}
			if (res10)
				fprintf(fout,"%lld %12.3Lf %3.0Lf %lld\n", tt-tt0, freq, phase, tt );
			else
				fprintf(fout,"%lld %12.2Lf %3.0Lf %lld\n", tt-tt0, freq, phase, tt );
			fflush(fout);
		}
#else
		if( termflag) {
			fprintf(fout,"%lld  %3.0Lf %lld\n", tt-tt0, phase2, tt );
			fprintf(fout,"%lld  %3.0Lf %lld\n", tt-tt0, phase3, tt );
			termflag = 0;
			fprintf(stdout, " ****");
		}
		fprintf(stdout,"\n%lld  %3.0Lf %lld", tt-tt0, phase, tt );
		if (tt != ott) {
			fprintf(stdout, " *");
			ott = tt;
			fprintf(fout,"%lld  %3.0Lf %lld\n", tt-tt0, phase, tt );
			fflush(fout);
		}
#endif
		++count;
	}
}
_______________________________________________
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.

Reply via email to