Console ApplicationsYou 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.
Links to other Hydra notes.
Introduction to the Hydra
Manual Operation
Setting The Hydra And The Computer To Communicate
General Computer Operation
Commands For A Single DC Voltage Measurement
Programming The Hydra In C++ (GUI/Visual Applications)
Programming The Hydra In Visual Basic
Programming The Hydra in LabView
Given a Hydra and a Wintel computer,
Be able to write console programs in C to measure DC voltages.
The Hydra should be turned on.
The Hydra and the computer should be set so that they can communcate.
You need to know the commands for a single DC voltage applications.
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:Once you have the files where you need them you are ready to build a project to take a measurement. Here are the steps.borlandc_gpib-32.obj
decl-32.h
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 (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>
#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.
Note the following about this program.
This line of code
HydraAddress = ibfind ("HYDRA")will determine the GPIB/IEEE-488 address of the Hydra - a number slightly greater than 32000. The int (integer) variable HydraAddress is assigned the value that is found and is used when communicating with the Hydra later in the program.
The ibwrt function is used to send command strings to the Hydra over the GPIB cable.
ibwrt (HydraAddress,"FUNC 0,VDC,AUTO",15);Here the ibwrt function sends a string to the Hydra (since HydraAddress is the first argument. That string sets the FUNCtion on Channel 0 to VDC - a DC voltage measurement. It also sets the Hydra to AUTOscale so that you don't have to specify the voltage scale which will be used to perform the measurement. Finally, you need to specify the number of characters that will be sent (15) in the last argument of ibwrt. Count them to be sure you understand how that works. Note that ibwrt is used to send a sequence of commands to the Hydra to take this measurement. Click here to review those commands.
To get the measurement into the computer, use the ibrd function. The C statement below reads 13 characters (max) into a character array called DCVoltsChar.
ibrd (HydraAddress, DCVoltsChar, 13);When the string is read into the computer you will probably want to convert the string to a number. To convert to a floating point number use atof (ASCII to float). Here's the code.
DCVolts = atof(DCVoltsChar);At this point you can do any of the things you can normally do with a floating point number including printing it to the screen (as the program above does) and writing that data to a file.
First, note that temperature cannot be measured from the front panel - Channel 0 -
and you will have to use one of the other channels.
Here's a line of code you can use. This sets the Hydra for a temperature
measurement. Everything else can stay the same in the program.ibwrt (hydra,""FUNC 1,TEMP,K"",13);This will measure TEMPerature using a type K thermocouple connected to Channel 1 on the connector strip cemented to the top of the Hydra DAU (See below.). You cannot measure temperature using a thermocouple and the front panel connectors.

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.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.
Hydra.h - A header file of prototypes for Hydra.c functions.
int Clear_Hydra(void);These functions will permit you to measure DCVolts, etc. with just one program line. Use this line in your program.float MeasureDCvolts_Hydra(int);
float MeasureACvolts_Hydra(int);
float MeasureOhms_Hydra(int);
float MeasureFrequency_Hydra(int);
float MeasureTemperature_Hydra(int);
#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 */Notes on these programs:
#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*/
}
All of these programs measure from the front panel except for temperature which measures from Channel 1. Feel free to change that as you wish.
There is excessive use of the reset command - *RST - in these functions. You may only need to reset the Hydra once when your program starts. Feel free to eliminate those extra commands to speed up your programs. Just remember that the Hydra buffer needs to be cleared out after each measurement is taken.
These functions are specific to the National Instruments board and will not work with any other board.
These programs were designed for the Borland C/C++ compiler and using borlandc_gpib-32.obj and decl-32.h will not work in other compilers or in Visual Basic. Also, be wary of dates on these files. Older versions may exist on the system.