|
|
@@ -15,6 +15,7 @@ |
|
|
|
#include "zoom.h" |
|
|
|
#include "math.h" |
|
|
|
|
|
|
|
void startup_zero(int zoom); |
|
|
|
void calibrate(int zoom, int gpib); |
|
|
|
#define info(x...) fprintf(stderr,x) |
|
|
|
|
|
|
@@ -27,17 +28,19 @@ int main(int argc, char *argv[]) |
|
|
|
char *gpibdev=strdup("/dev/ttyUSB0"); |
|
|
|
int getopt_index; |
|
|
|
int zoom, gpib; |
|
|
|
int do_zero = 0; |
|
|
|
|
|
|
|
static struct option long_opts[] = { |
|
|
|
{ "zoom-device", required_argument, NULL, 'z' }, |
|
|
|
{ "gpib-device", required_argument, NULL, 'g' }, |
|
|
|
{ "startup-zero", required_argument, NULL, 's' }, |
|
|
|
{ "help", no_argument, NULL, 'h' }, |
|
|
|
{ 0, 0, 0, 0 } |
|
|
|
}; |
|
|
|
int help=0; |
|
|
|
char c; |
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, "z:g:h?", |
|
|
|
while ((c = getopt_long(argc, argv, "z:g:sh?", |
|
|
|
long_opts, &getopt_index)) != -1) { |
|
|
|
switch(c) |
|
|
|
{ |
|
|
@@ -49,6 +52,9 @@ int main(int argc, char *argv[]) |
|
|
|
free(gpibdev); |
|
|
|
gpibdev = strdup(optarg); |
|
|
|
break; |
|
|
|
case 's': |
|
|
|
do_zero = 1; |
|
|
|
break; |
|
|
|
case 'h': |
|
|
|
case '?': |
|
|
|
default: |
|
|
@@ -62,12 +68,22 @@ int main(int argc, char *argv[]) |
|
|
|
fprintf(stderr, "usage: %s [options]\n\n", *argv); |
|
|
|
fprintf(stderr, " -z, --zoom-device %-14s zoom NILM serial port\n", zoomdev); |
|
|
|
fprintf(stderr, " -g, --gpib-device %-14s GPIB serial port\n", gpibdev); |
|
|
|
fprintf(stderr, " -h, --help this help\n"); |
|
|
|
fprintf(stderr, " -s, --startup-zero assist startup by writing '0' to zoom NILM\n"); |
|
|
|
fprintf(stderr, " -h, --help this help\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
signal(SIGINT, handle_sig); |
|
|
|
|
|
|
|
if ((zoom = serial_open(zoomdev, 115200)) == -1) |
|
|
|
err(1, "failed to open zoom device %s", zoomdev); |
|
|
|
|
|
|
|
if (do_zero) { |
|
|
|
startup_zero(zoom); |
|
|
|
close(zoom); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
if ((gpib = serial_open(gpibdev, 9600)) == -1) |
|
|
|
err(1, "failed to open gpib device %s", gpibdev); |
|
|
|
|
|
|
@@ -107,12 +123,13 @@ void calibrate(int zoom, int gpib) |
|
|
|
if (zoom_zero_stop(zoom) < 0) goto fail; |
|
|
|
|
|
|
|
info("Sweeping\n"); |
|
|
|
for (idesired = -1.0; idesired <= 1.0 && !g_quit; idesired += 0.100) { |
|
|
|
for (idesired = -1.0; idesired <= 1.0 && !g_quit; idesired += 0.05) { |
|
|
|
info("Zeroing\n"); |
|
|
|
if (zoom_zero_start(zoom) < 0) goto fail; |
|
|
|
|
|
|
|
info("Setting current: %.8f\n", idesired); |
|
|
|
keithley_current(gpib, idesired); |
|
|
|
usleep(100000); |
|
|
|
iactual = keithley_read(gpib); |
|
|
|
info("Actual current: %.8f\n", iactual); |
|
|
|
|
|
|
@@ -140,3 +157,21 @@ fail: |
|
|
|
info("Failed (code %d)\n", r); |
|
|
|
goto safecleanup; |
|
|
|
} |
|
|
|
|
|
|
|
void startup_zero(int zoom) |
|
|
|
{ |
|
|
|
char buf[128]; |
|
|
|
|
|
|
|
if (zoom_init(zoom) < 0) |
|
|
|
errx(1, "init"); |
|
|
|
|
|
|
|
while (!g_quit) { |
|
|
|
buf[0] = '0'; |
|
|
|
if (safewrite(zoom, buf, 1) != 1) |
|
|
|
errx(1, "write"); |
|
|
|
if (fdgets(buf, 128, zoom, 1000) == NULL) |
|
|
|
errx(1, "read timeout"); |
|
|
|
chomp(buf); |
|
|
|
printf("%s\n", buf); |
|
|
|
} |
|
|
|
} |