/* $Id: hvsupply.c,v 1.2 2004/04/03 04:17:37 jmuelmen Exp $ */ #include #include #include #include #ifndef DUMMY_INST #include #include "Decl-32.h" #endif #include "inst.h" #include "instinit.h" #include "trace.h" static long dev = -1; static pthread_mutex_t mut; #define PS_LOCK pthread_mutex_lock(&mut) #define PS_UNLOCK pthread_mutex_unlock(&mut) /* High-voltage supply code from Hans-Christian Kaestli */ int hvsupply_init () { #ifndef DUMMY_INST char s[100]; trace_output("Initializing HV supply at device 10... "); dev = ibdev(0,10,0,T3s,1,0); ibwrt(dev, "*rst\r", strlen("*rst\r")); sprintf(s, "*idn?\r"); ibwrt(dev, s, strlen(s)); ibrd(dev, s, 100); trace_output("%s.\n", s); ibwrt(dev, "*rst\r", strlen("*rst\r")); sprintf(s, ":SOUR:VOLT:RANG 1000\r"); ibwrt(dev, s, strlen(s)); pthread_mutex_init(&mut, NULL); #endif return 0; } int hvsupply_enable (int enable) { #ifndef DUMMY_INST char s[100]; PS_LOCK; if(enable==1) { sprintf(s, ":OUTP ON\r"); ibwrt(dev, s, strlen(s)); } if(enable==0){ sprintf(s, ":OUTP OFF\r"); ibwrt(dev, s, strlen(s)); } PS_UNLOCK; #endif return 0; } int hvsupply_set_voltage (double v) { #ifndef DUMMY_INST char s[100]; PS_LOCK; sprintf(s, ":SOUR:VOLT %f", v); ibwrt(dev, s, strlen(s)); PS_UNLOCK; return 0; #endif } double hvsupply_get_current () { #ifndef DUMMY_INST char s[100]; PS_LOCK; sprintf(s, ":SENS:FUNC 'CURR:DC'\r"); ibwrt(dev, s, strlen(s)); sprintf(s, ":SENS:DATA:FRES?\r"); ibwrt(dev, s, strlen(s)); ibrd(dev, s, 100); trace_output("%s.\n", s); PS_UNLOCK; return atof(s); #else return 0; #endif } double hvsupply_get_voltage () { #ifndef DUMMY_INST char s[100]; PS_LOCK; sprintf(s, ":SENS:FUNC 'VOLT:DC'\r"); ibwrt(dev, s, strlen(s)); sprintf(s, ":SENS:DATA:FRES?\r"); ibwrt(dev, s, strlen(s)); ibrd(dev, s, 100); trace_output("%s.\n", s); PS_UNLOCK; return atof(s); #else return 0; #endif }