hydra gpib c program

Download Hydra GPIB C Program

If you can't read please download the document

Upload: sure

Post on 16-Jan-2016

213 views

Category:

Documents


0 download

DESCRIPTION

gpib code

TRANSCRIPT

/* Example C Program to interface to Fluke Hydra Data Acquisition System using IEEE-488 port *//*********************************************************************************************///---------------------------------------------------------------------------#include /* standard I/O library functions */#include /* need math.h for atof function */#include #include #include "decl-32.h"#pragma hdrstop//---------------------------------------------------------------------------#pragma argsusedint main(int argc, char* argv[]){int HydraAddress;float DCVolts;char DCVoltsChar[13];HydraAddress = ibfind ("HYDRA"); /* find the HYDRA DAU */ibwrt (HydraAddress, "*RST", 4); /* reset the HYDRA DAU */ibwrt (HydraAddress,"FUNC 0,VDC,AUTO",15); /* Channel 0, Auto Range */ibwrt (HydraAddress, "*TRG", 4); /* trigger voltage meas. */ibwrt (HydraAddress, "LAST? 0", 7); /* prompt for last meas. */ibrd (HydraAddress, DCVoltsChar, 13); /* voltage string */DCVolts = atof(DCVoltsChar); /* string to floating pt.*/printf("DC Voltage Measured = %f volts.", DCVolts);while (!kbhit()) { }return 0;}//---------------------------------------------------------------------------/*This program is designed for the Borland C/C++ compiler and usesborlandc_gpib-32.obj and decl-32.h These obj and decl-32.h will not work in other compilers or in Visual Basic*//*********************************************************************//*Header file Hydra.h used in the C code below is as follows:int Clear_Hydra(void);float MeasureDCvolts_Hydra(int);float MeasureACvolts_Hydra(int);float MeasureOhms_Hydra(int);float MeasureFrequency_Hydra(int);float MeasureTemperature_Hydra(int);*//*********************************************************************//* The Hydra.C file is as below*/#include /* standard I/O library functions */#include /* contains the write function */#include /* contains the atof function */#include /* contains the sleep function */#include * contains access flags for 'open' */#include /* contains access modes for 'open' */#include /* contains all time functions */#include /* contains all str functions */#include /* contains the exit() function */#include "hydra.h" /* function declaration file */#include #include "decl-32.h" /* header declaration file *//* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */int Clear_Hydra(){/* Subroutine to reset the FLUKE HYDRA 2620A Data Acquisition Unit. */int hydra,i; /* variable declaration */hydra = ibfind ("HYDRA"); /* find the HYDRA DAU/get handle */ibwrt (hydra, "*RST", 4); /* reset the HYDRA DAU */return hydra; /* return hydra handle */}float MeasureDCvolts_Hydra(int hydra){/* Subroutine to measure DC volts on the front panel (Channel 0) of the *//* FLUKE HYDRA 2620A Data Acqusition Unit. "hydra" must be sent down *//* from function main. Value is returned as "volts". */float volts; /* variable declarations */char volts_char[13];ibwrt (hydra,"FUNC 0,VDC,AUTO",15); /* Channel 0, Auto Range */ibwrt (hydra, "*TRG", 4); /* trigger voltage meas. */ibwrt (hydra, "LAST? 0", 7); /* prompt for last meas. */ibrd (hydra, volts_char, 13); /* voltage string */volts = atof (volts_char); /* string to floating pt. */ibwrt (hydra, "*RST", 4); /* reset HYDRA *//* Eliminate the reset to speed this up. *//* You can also eliminate the FUNC statement once the Hydra is set. *//* Use another name for the function if you change anything. */return volts; /* return measured voltage */}float MeasureACvolts_Hydra(int hydra){/* Subroutine to measure AC volts on the front panel (Channel 0) of the *//* FLUKE HYDRA 2620A Data Acqusition Unit. "hydra" must be sent down *//* from function main. Value is returned as "volts". */float volts; /* variable declarations */char volts_char[13];ibwrt (hydra,"FUNC 0,VAC,AUTO",15); /* Channel 0, Auto Range */ibwrt (hydra, "*TRG", 4); /* trigger voltage meas. */ibwrt (hydra, "LAST? 0", 7); /* prompt for last meas. */ibrd (hydra, volts_char, 13); /* voltage string */volts = atof (volts_char); /* string to floating pt.*/ibwrt (hydra, "*RST", 4); /* reset HYDRA */return volts; /* return value */}float MeasureOhms_Hydra(int hydra){/* Subroutine to measure two-wire-ohms resistance on the front panel *//* (Channel 0) of the FLUKE HYDRA 2620A Data Acqusition Unit. "hydra"*//* must be sent down from function main. Value is returned as *//* "resistance". */float resistance; /* variable declarations */char ohms_char[13];ibwrt (hydra,"FUNC 0,OHMS,AUTO,2",18); /* Chan. 0, Auto, 2-Wire */ibwrt (hydra, "*TRG", 4); /* trigger ohms meas. */ibwrt (hydra, "LAST? 0", 7); /* prompt for last meas. */ibrd (hydra, ohms_char, 13); /* ohms string */resistance = atof (ohms_char); /* string to floating pt.*/ibwrt (hydra, "*RST", 4); /* reset HYDRA */return resistance; /* return value */}float MeasureFrequency_Hydra(int hydra){/* Subroutine to measure frequency on the front panel (Channel 0) of the *//* FLUKE HYDRA 2620A Data Acqusition Unit. Value is returned as *//* "frequency". "hydra" must be sent down from function main. */float frequency; /* variable declarations */char freq_char[13];ibwrt (hydra,"FUNC 0,FREQ,AUTO",16); /* Chan. 0, Auto Range */ibwrt (hydra, "*TRG", 4); /* trigger freq. meas. */ibwrt (hydra, "LAST? 0", 7); /* prompt for last meas. */ibrd (hydra, freq_char, 13); /* frequency string */frequency = atof (freq_char); /* string to floating pt.*/ibwrt (hydra, "*RST", 4); /* reset HYDRA */return frequency; /* return value */}float MeasureTemperature_Hydra(int hydra){/* Subroutine to measure frequency on the front panel (Channel 1) of the *//* FLUKE HYDRA 2620A Data Acqusition Unit. Value is returned as *//* "temperature". "hydra" must be sent down from function main. */float temperature; /* variable declarations */char temp_char[13];ibwrt (hydra,"FUNC 1,TEMP,K",13); /* Chan. 1, Type K Thermocouple */ibwrt (hydra, "*TRG", 4); /* trigger TEMP meas. */ibwrt (hydra, "LAST? 1", 7); /* prompt for last meas on Ch 1 */ibrd (hydra, temp_char, 13); /* temperature string */temperature = atof (temp_char); /* string to floating pt */ibwrt (hydra, "*RST", 4); /* reset HYDRA *//* Eliminate the reset to speed this up. *//* You can also eliminate the FUNC statement once the Hydra is set. *//* Use another name for the function if you change anything. */return temperature; /* return measured value*/}