|
@@ -11,11 +11,9 @@ |
|
|
#include <linux/serial.h> |
|
|
#include <linux/serial.h> |
|
|
#include <sys/signal.h> |
|
|
#include <sys/signal.h> |
|
|
#include "serial-util.h" |
|
|
#include "serial-util.h" |
|
|
|
|
|
#include "gpib.h" |
|
|
|
|
|
|
|
|
int zoom, gpib; |
|
|
|
|
|
|
|
|
|
|
|
void calibrate(void); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void calibrate(int zoom, int gpib); |
|
|
#define info(x...) fprintf(stderr,x) |
|
|
#define info(x...) fprintf(stderr,x) |
|
|
|
|
|
|
|
|
int quit = 0; |
|
|
int quit = 0; |
|
@@ -29,6 +27,7 @@ int main(int argc, char *argv[]) |
|
|
char *zoomdev=strdup("/dev/ttyUSB1"); |
|
|
char *zoomdev=strdup("/dev/ttyUSB1"); |
|
|
char *gpibdev=strdup("/dev/ttyUSB0"); |
|
|
char *gpibdev=strdup("/dev/ttyUSB0"); |
|
|
int getopt_index; |
|
|
int getopt_index; |
|
|
|
|
|
int zoom, gpib; |
|
|
|
|
|
|
|
|
static struct option long_opts[] = { |
|
|
static struct option long_opts[] = { |
|
|
{ "zoom-device", required_argument, NULL, 'z' }, |
|
|
{ "zoom-device", required_argument, NULL, 'z' }, |
|
@@ -39,16 +38,6 @@ int main(int argc, char *argv[]) |
|
|
int help=0; |
|
|
int help=0; |
|
|
char c; |
|
|
char c; |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
char buf[1024]; |
|
|
|
|
|
drain(0); |
|
|
|
|
|
fdprintf(1,"type a string in 5 sec: "); |
|
|
|
|
|
fdgets(buf, 1024, 0, 5000); |
|
|
|
|
|
chomp(buf); |
|
|
|
|
|
fdprintf(1,"you typed: '%s' len %d\n", buf, strlen(buf)); |
|
|
|
|
|
abort(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, "z:g:h?", |
|
|
while ((c = getopt_long(argc, argv, "z:g:h?", |
|
|
long_opts, &getopt_index)) != -1) { |
|
|
long_opts, &getopt_index)) != -1) { |
|
|
switch(c) |
|
|
switch(c) |
|
@@ -84,75 +73,31 @@ int main(int argc, char *argv[]) |
|
|
errx(1, "gpib open failed"); |
|
|
errx(1, "gpib open failed"); |
|
|
|
|
|
|
|
|
signal(SIGINT, handle_sig); |
|
|
signal(SIGINT, handle_sig); |
|
|
calibrate(); |
|
|
|
|
|
|
|
|
calibrate(zoom, gpib); |
|
|
|
|
|
|
|
|
close(zoom); |
|
|
close(zoom); |
|
|
close(gpib); |
|
|
close(gpib); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void gputs(char *s) |
|
|
|
|
|
|
|
|
void calibrate(int zoom, int gpib) |
|
|
{ |
|
|
{ |
|
|
info("%s\n", s); |
|
|
|
|
|
if (write(gpib, s, strlen(s)) != strlen(s) || |
|
|
|
|
|
write(gpib, "\r", 1) != 1) |
|
|
|
|
|
err(1, "error writing GPIB string '%s'", s); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
float i; |
|
|
|
|
|
|
|
|
void keithley_on(void) |
|
|
|
|
|
{ |
|
|
|
|
|
gputs("++mode 1"); |
|
|
|
|
|
gputs("++auto 0"); |
|
|
|
|
|
gputs("++eos 1"); |
|
|
|
|
|
gputs("++eoi 1"); |
|
|
|
|
|
gputs("++read_tmo_ms 4000"); |
|
|
|
|
|
gputs("++eot_enable 1"); |
|
|
|
|
|
gputs("++eot_char 13"); |
|
|
|
|
|
gputs("++addr 24"); |
|
|
|
|
|
gputs(":syst:beep:stat 0"); |
|
|
|
|
|
gputs(":sour:func:mode curr"); |
|
|
|
|
|
gputs(":sour:del 0"); |
|
|
|
|
|
gputs(":sour:curr 0"); |
|
|
|
|
|
gputs(":sour:curr:range:auto on"); |
|
|
|
|
|
gputs(":outp on"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void keithley_current(int ma) |
|
|
|
|
|
{ |
|
|
|
|
|
char s[128]; |
|
|
|
|
|
sprintf(s, ":sour:curr %0.3f", ma / 1000.0); |
|
|
|
|
|
gputs(s); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void keithley_off(void) |
|
|
|
|
|
{ |
|
|
|
|
|
gputs(":outp off"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void zputc(char ch) |
|
|
|
|
|
{ |
|
|
|
|
|
if (write(zoom, &ch, 1) != 1) |
|
|
|
|
|
err(1, "zoom write"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void zero(void) |
|
|
|
|
|
{ |
|
|
|
|
|
zputc('z'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void calibrate(void) |
|
|
|
|
|
{ |
|
|
|
|
|
int ma; |
|
|
|
|
|
|
|
|
info("Initializing GPIB\n"); |
|
|
|
|
|
gpib_init(gpib); |
|
|
|
|
|
|
|
|
info("Initializing Keithley\n"); |
|
|
info("Initializing Keithley\n"); |
|
|
keithley_on(); |
|
|
|
|
|
|
|
|
gpib_addr(gpib, 24); |
|
|
|
|
|
keithley_init(gpib); |
|
|
|
|
|
|
|
|
info("Sweep\n"); |
|
|
info("Sweep\n"); |
|
|
for (ma = -1000; ma <= 1000; ma += 10) { |
|
|
|
|
|
keithley_current(ma); |
|
|
|
|
|
usleep(100000); |
|
|
|
|
|
|
|
|
for (i = -1.0; i <= 1.0; i += 0.01) { |
|
|
|
|
|
keithley_current(gpib, i); |
|
|
|
|
|
printf("requested %f, actual %f\n", i, keithley_read(gpib)); |
|
|
|
|
|
usleep(10000); |
|
|
if (quit) break; |
|
|
if (quit) break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
keithley_off(); |
|
|
|
|
|
|
|
|
keithley_off(gpib); |
|
|
} |
|
|
} |