Programming the Hydra Data Acquisition Unit in C

Console Applications
        You can program the Hydra in C in two modes - programming for console applications (i.e. using the keyboard in a command-line situation) and programming for graphical GUI (Visual) applications.  This note describes how to program in C for console applications.  The specific example is taking a single DC voltage measurement.

GOALS

    Given a Hydra and a Wintel computer,
    Be able to write console programs in C to measure DC voltages.

What You Need

The Hydra should be turned on.

The Hydra and the computer should be set so that they can communcate.

        If you have taken care of all of the above, then you need to do the following.

Establish a directory for your work.  It is strongly recommend that you put that directory on the hard drive of the computer you use.  All of the files will not fit on a diskette, and you may have problems in you use your network space.  If you use your network space and your program performs erratically or freezes your computer you will receive no sympathy from your instructor or lab assistant.  Reboot and do not complain.

Copy two files into that directory.  Those files may be on the machine you are using, and they are also available in E. J. Mastascusa's public space on the network.  Here is the complete path:

    Network Neighborhood
        Entire Network
            Academic_depts
                mastascu
                    public
                        Labs
                            Instruments
                                Hydra

    The files you need are:
borlandc_gpib-32.obj
decl-32.h
Once you have the files where you need them you are ready to build a project to take a measurement.  Here are the steps.
Start the Borland C compiler on your computer.

Choose Project - Add New Project from the menu.

A new window appears labelled New Items.

In that window select Console Wizard, and click OK.

Choose C from the options and click OK.

A new window appears with the following code.

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[ ])
{
        return 0;
}
//---------------------------------------------------------------------------

You will need to enter code into the main function.

You may enter any other functions you might want as well.

Add the file borlandc_gpib-32.obj to the project by clicking Project - Add to Project and selecting the file.  You may need to set the file filter to *.obj to find the file, then select the file and click Open.

Now enter C code in the main program.  Here is some code to get you started.  The code in red is what is added to the default code above.  You can copy any part or all of this code.

//---------------------------------------------------------------------------
#include <stdio.h>    /* standard I/O library functions   */
#include <math.h>     /* need math.h for atof function  */
#include <conio.h>
#include <windows.h>
#include "decl-32.h"
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
int 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;
}
//---------------------------------------------------------------------------

The file decl32.h is used only in this include statement.  (If you add this file to your project (See above where you added an object file!) you will have problems and your instructor will not be sympathetic.)  The quotation marks around the file indicate that this header (*.h) file is in the same directory as the rest of your files.  If you put it elsewhere you will need to supply path information.  It's blinking in the listing so you will remember the important points about decl32.h.

To make an executable file, use Project - Make.  That will compile any files that have changed since the last time you used Make.  NOTE:  Using Project - Build will force a complete re-compile of everything in your project whether or not it has been changed.  There may be times when that is desirable, but normally you will use Make.



Notes On Programming In C

        Note the following about this program.


What if you want to measure a temperature?

Things You May Want To Know

        A small library of functions for the Hydra has been written.

Hydra.c - Functions to find and clear the Hydra and Measure DC Volts, ACVolts, Resistance and Frequency.
Hydra.h -  A header file of prototypes for Hydra.c functions.
Here is the Hydra.h file.  Copy the text into a text editor and save the file as Hydra.h in the directory where you do your C/C++ work.
int Clear_Hydra(void);

float MeasureDCvolts_Hydra(int);
float MeasureACvolts_Hydra(int);
float MeasureOhms_Hydra(int);
float MeasureFrequency_Hydra(int);
float MeasureTemperature_Hydra(int);

These functions will permit you to measure DCVolts, etc. with just one program line.  Use this line in your program.
#include "hydra.h"
Here are the functions in their entirety.  Copy this text into a file Hydra.c in your working directory.
#include <stdio.h>  /* standard I/O library functions      */
#include <io.h>   /* contains the write function         */
#include <math.h>  /* contains the atof function          */
#include <dos.h>  /* contains the sleep function         */
#include <fcntl.h>  * contains access flags for 'open'    */
#include <sys\stat.h>  /* contains access modes for 'open'    */
#include <time.h>  /* contains all time functions         */
#include <string.h>  /* contains all str functions          */
#include <stdlib.h>  /* contains the exit() function        */
#include "hydra.h"  /* function declaration file           */
#include <windows.h>
#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*/
}

Notes on these programs:
Links to other Hydra notes.