home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /* Copyright 1996 National Instruments Corporation. All Rights Reserved. */
- /*****************************************************************************/
-
- #include <visa.h>
- #include <ansi_c.h>
- #include <string.h>
- #include <formatio.h>
- #include "fl45.h"
-
- #define fl45_REVISION "Rev 1.0, 9/95, CVI 3.1" /* Instrument driver revision */
- #define BUFFER_SIZE 512L /* File I/O buffer size */
-
- /*===========================================================================*/
- /*= Fluke 45 Digital Multimeter (VISA I/O) ==================================*/
- /* LabWindows/CVI 3.1 Instrument Driver */
- /* Original Release: September 1995 */
- /* By: JRO, National Instruments, Austin Texas */
- /* PH. (800)433-3488 Fax (512)794-5678 */
- /* */
- /* Modification History: */
- /* */
- /* June 1995 - Modified the LabWindows/CVI instrument driver to use */
- /* VISA I/O calls. */
- /* */
- /* Modified by: JRO, National Instruments, Austin, Texas */
- /* */
- /*===========================================================================*/
-
- /*****************************************************************************/
- /*= INSTRUMENT-DEPENDENT COMMAND ARRAYS =====================================*/
- /*****************************************************************************/
- static ViString primDispFunc[10] = {"AAC","AACDC","ADC","CONT","DIODE","FREQ","OHMS","VAC","VACDC","VDC"};
- static ViString secDispFunc[8] = {"AAC2","ADC2","DIODE2","FREQ2","OHMS2","VAC2","VDC2","CLR2"};
- static ViString primDispRange[2] = {"FIXED","AUTO"};
- static ViString primDispRate[3] = {"S","M","F"};
- static ViString decibel[4] = {"DBCLR","DB; DBREF","DBREF","DBPOWER"};
- static ViString minMaxSet[5] = {"MMCLR","MIN","MINSET","MAX","MAXSET"};
- static ViString relative[3] = {"RELCLR","REL","RELSET"};
-
- /*****************************************************************************/
- /*= UTILITY ROUTINE DECLARATIONS (Non-Exportable Functions) =================*/
- /*****************************************************************************/
- ViBoolean fl45_invalidViBooleanRange (ViBoolean val);
- ViBoolean fl45_invalidViInt16Range (ViInt16 val, ViInt16 min, ViInt16 max);
- ViBoolean fl45_invalidViInt32Range (ViInt32 val, ViInt32 min, ViInt32 max);
- ViBoolean fl45_invalidViUInt16Range (ViUInt16 val, ViUInt16 min, ViUInt16 max);
- ViBoolean fl45_invalidViUInt32Range (ViUInt32 val, ViUInt32 min, ViUInt32 max);
- ViBoolean fl45_invalidViReal32Range (ViReal32 val, ViReal32 min, ViReal32 max);
- ViBoolean fl45_invalidViReal64Range (ViReal64 val, ViReal64 min, ViReal64 max);
- ViStatus fl45_initCleanUp (ViSession openRMSession, ViPSession openInstrSession, ViStatus currentStatus);
- ViStatus fl45_readToFile (ViSession instrSession, ViString filename, ViUInt32 readBytes, ViPUInt32 retCount);
- ViStatus fl45_writeFromFile (ViSession instrSession, ViString filename, ViUInt32 writeBytes, ViPUInt32 retCount);
- ViStatus fl45_instrStatus (ViSession instrSession);
- ViStatus fl45_defaultInstrSetup (ViSession openInstrSession);
-
- /*****************************************************************************/
- /*= INSTRUMENT-DEPENDENT STATUS/RANGE STRUCTURE ============================*/
- /*****************************************************************************/
- /* fl45_stringValPair is used in the PREFIX_errorMessage function */
- /* fl45_statusDataRanges is used to track session dependent status & ranges */
- /*===========================================================================*/
- typedef struct fl45_stringValPair
- {
- ViStatus stringVal;
- ViString stringName;
- } fl45_tStringValPair;
-
- struct fl45_statusDataRanges {
- ViInt16 primeDispStatus;
- ViInt16 secDispStatus;
- ViInt16 trigStatus;
- ViChar instrDriverRevision[256];
- };
-
- typedef struct fl45_statusDataRanges *fl45_instrRange;
-
- /*****************************************************************************/
- /*====== USER-CALLABLE FUNCTIONS (Exportable Functions) =====================*/
- /*****************************************************************************/
-
- /*===========================================================================*/
- /* Function: Initialize */
- /* Purpose: This function opens the instrument, queries the instrument for */
- /* its ID, and initializes the instrument to a known state. */
- /*===========================================================================*/
- ViStatus _VI_FUNC fl45_init (ViRsrc resourceName, ViBoolean IDQuery,
- ViBoolean reset, ViPSession instrSession)
- {
- ViStatus fl45_status = VI_SUCCESS;
- ViSession rmSession = 0;
- ViUInt32 retCnt = 0;
- ViByte rdBuffer[BUFFER_SIZE];
-
- /*- Check input parameter ranges ----------------------------------------*/
- if (fl45_invalidViBooleanRange (IDQuery))
- return VI_ERROR_PARAMETER2;
- if (fl45_invalidViBooleanRange (reset))
- return VI_ERROR_PARAMETER3;
-
- /*- Open instrument session ---------------------------------------------*/
- if ((fl45_status = viOpenDefaultRM (&rmSession)) < 0)
- return fl45_status;
-
- if ((fl45_status = viOpen (rmSession, resourceName, VI_NULL, VI_NULL, instrSession)) < 0) {
- viClose (rmSession);
- return fl45_status;
- }
-
- /*- Configure VISA Formatted I/O ----------------------------------------*/
- if ((fl45_status = viSetAttribute (*instrSession, VI_ATTR_TMO_VALUE, 10000)) < 0)
- return fl45_initCleanUp (rmSession, instrSession, fl45_status);
- if ((fl45_status = viSetBuf (*instrSession, VI_READ_BUF|VI_WRITE_BUF, 4000)) < 0)
- return fl45_initCleanUp (rmSession, instrSession, fl45_status);
- if ((fl45_status = viSetAttribute (*instrSession, VI_ATTR_WR_BUF_OPER_MODE,
- VI_FLUSH_ON_ACCESS)) < 0)
- return fl45_initCleanUp (rmSession, instrSession, fl45_status);
- if ((fl45_status = viSetAttribute (*instrSession, VI_ATTR_RD_BUF_OPER_MODE,
- VI_FLUSH_ON_ACCESS)) < 0)
- return fl45_initCleanUp (rmSession, instrSession, fl45_status);
-
- /*- Identification Query ------------------------------------------------*/
- if (IDQuery) {
- if ((fl45_status = viWrite (*instrSession, "*IDN?", 5, &retCnt)) < 0)
- return fl45_initCleanUp (rmSession, instrSession, fl45_status);
- if ((fl45_status = viRead (*instrSession, rdBuffer, BUFFER_SIZE, &retCnt)) < 0)
- return fl45_status;
-
- Scan (rdBuffer, "FLUKE, 45");
- if (NumFmtdBytes () != 9)
- return fl45_initCleanUp (rmSession, instrSession, VI_ERROR_FAIL_ID_QUERY);
- }
-
- /*- Reset instrument ----------------------------------------------------*/
- if (reset) {
- if ((fl45_status = fl45_reset (*instrSession)) < 0)
- return fl45_initCleanUp (rmSession, instrSession, fl45_status);
- }
- else /*- Send Default Instrument Setup ---------------------------------*/
- if ((fl45_status = fl45_defaultInstrSetup (*instrSession)) < 0)
- return fl45_initCleanUp (rmSession, instrSession, fl45_status);
-
- if (fl45_instrStatus (*instrSession) != VI_SUCCESS)
- return fl45_initCleanUp (rmSession, instrSession, fl45_status);
-
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: Setup and Read Measurements */
- /* Purpose: This function configures the primary and secondary display. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_applicReadMeas (ViSession instrSession, ViBoolean rdOnly, ViInt16 setPrimDisp, ViInt16 setSecDisp, ViPReal64 rdPrimDisp, ViPReal64 rdSecDisp)
- {
- ViStatus fl45_status = VI_SUCCESS;
- fl45_instrRange instrPtr;
-
- if (fl45_invalidViBooleanRange (rdOnly))
- return VI_ERROR_PARAMETER2;
- if (fl45_invalidViInt16Range (setPrimDisp, 0, 9))
- return VI_ERROR_PARAMETER3;
- if (fl45_invalidViInt16Range (setSecDisp, 0, 7))
- return VI_ERROR_PARAMETER4;
-
- if ((fl45_status = viGetAttribute (instrSession, VI_ATTR_USER_DATA, &instrPtr)) < 0)
- return fl45_status;
-
- if (!rdOnly)
- if ((fl45_status = fl45_configMeas (instrSession, setPrimDisp, setSecDisp)) < 0)
- return fl45_status;
- if ((fl45_status = fl45_measPrimDisp (instrSession, VI_OFF, rdPrimDisp)) < 0)
- return fl45_status;
-
- if (instrPtr -> secDispStatus)
- if ((fl45_status = fl45_measSecDisp (instrSession, VI_OFF, rdSecDisp)) < 0)
- return fl45_status;
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: Primary and Secondary Display Configuration */
- /* Purpose: This function configures the primary and secondary display. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_configMeas (ViSession instrSession, ViInt16 func1, ViInt16 func2)
- {
- ViStatus fl45_status = VI_SUCCESS;
- fl45_instrRange instrPtr;
-
- if (fl45_invalidViInt16Range (func1, 0, 9))
- return VI_ERROR_PARAMETER2;
- if (fl45_invalidViInt16Range (func2, 0, 7))
- return VI_ERROR_PARAMETER3;
-
- if ((fl45_status = viGetAttribute (instrSession, VI_ATTR_USER_DATA, &instrPtr)) < 0)
- return fl45_status;
-
- if (((func1 == 1) || (func1 == 8)) && (func2 != 7)) {
- fl45_status = VI_ERROR_CONFIGURE_ERROR;
- return fl45_status;
- }
-
- if ((fl45_status = viPrintf (instrSession, "%s; %s;", primDispFunc[func1], secDispFunc[func2])) < 0)
- return fl45_status;
-
- instrPtr -> primeDispStatus = func1;
- if (func2 < 7)
- instrPtr -> secDispStatus = 1;
- else
- instrPtr -> secDispStatus = 0;
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: Range Configuration */
- /* Purpose: This function configures the autoRange, and sensitivity */
- /* (if autoRange is off). */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_configRange (ViSession instrSession, ViBoolean autoRange, ViInt16 sens)
- {
- ViStatus fl45_status = VI_SUCCESS;
- fl45_instrRange instrPtr;
- ViInt16 n;
- ViUInt32 retCnt = 0;
- ViByte writeBuffer[BUFFER_SIZE];
-
- if (fl45_invalidViBooleanRange (autoRange))
- return VI_ERROR_PARAMETER2;
- if (fl45_invalidViInt16Range (sens, 1, 8))
- return VI_ERROR_PARAMETER3;
-
- if ((fl45_status = viGetAttribute (instrSession, VI_ATTR_USER_DATA, &instrPtr)) < 0)
- return fl45_status;
- if ((autoRange == 1) && ((instrPtr -> primeDispStatus == 3)
- || (instrPtr -> primeDispStatus == 4))) {
- return VI_ERROR_CONFIGURE_ERROR;
- }
-
- if ((fl45_status = viWrite (instrSession, "MOD?", 4, &retCnt)) < 0)
- return fl45_status;
- if ((fl45_status = viScanf (instrSession, "%hd", &n)) < 0)
- return fl45_status;
- if ((autoRange == 1) && ((n & 0x3B) != 0))
- return VI_ERROR_CONFIGURE_RANGE;
-
-
- if (autoRange == 0 && sens < 8)
- Fmt (writeBuffer, "%s<%s;RANGE %d[b2]", primDispRange[autoRange], sens);
- else
- Fmt(writeBuffer,"%s<%s", primDispRange[autoRange]);
-
- if ((fl45_status = viWrite (instrSession, writeBuffer, NumFmtdBytes(), &retCnt)) < 0)
- return fl45_status;
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: Trigger Configuration */
- /* Purpose: This function configures the measurement rate and trigger. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_configTrig (ViSession instrSession, ViInt16 trig, ViInt16 rate)
- {
- ViStatus fl45_status = VI_SUCCESS;
- fl45_instrRange instrPtr;
-
- if (fl45_invalidViInt16Range (trig, 1, 5))
- return VI_ERROR_PARAMETER2;
- if (fl45_invalidViInt16Range (rate, 0, 2))
- return VI_ERROR_PARAMETER3;
-
- if ((fl45_status = viGetAttribute (instrSession, VI_ATTR_USER_DATA, &instrPtr)) < 0)
- return fl45_status;
-
- if ((fl45_status = viPrintf (instrSession, "TRIGGER %hd;RATE %s;", trig, primDispRate[rate])) < 0)
- return fl45_status;
-
- instrPtr -> trigStatus = trig;
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
- /*=========================================================================*/
- /* Function: Compare */
- /* Purpose: This function turns the Compare modifier on or off. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_configCompare (ViSession instrSession, ViBoolean comp, ViReal64 comp_lo, ViReal64 comp_hi)
- {
- ViStatus fl45_status = VI_SUCCESS;
- ViUInt32 retCnt = 0;
- ViByte writeBuffer[BUFFER_SIZE];
-
- if (fl45_invalidViBooleanRange (comp))
- return VI_ERROR_PARAMETER2;
- if (fl45_invalidViReal64Range (comp_lo, -2.0e7, 2.0e7))
- return VI_ERROR_PARAMETER3;
- if (fl45_invalidViReal64Range (comp_hi, -2.0e7, 2.0e7))
- return VI_ERROR_PARAMETER4;
-
- if (comp == 0)
- Fmt (writeBuffer, "%s<COMPCLR");
- else
- Fmt (writeBuffer, "%s<COMP; COMPLO %f; COMPHI %f; HOLD;", comp_lo, comp_hi);
-
- if ((fl45_status = viWrite (instrSession, writeBuffer, NumFmtdBytes(), &retCnt)) < 0)
- return fl45_status;
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: Hold */
- /* Purpose: This function turns the Touch Hold modifier on or off. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_configHold (ViSession instrSession, ViBoolean hold, ViInt16 hold_thresh)
- {
- ViStatus fl45_status = VI_SUCCESS;
- ViUInt32 retCnt = 0;
- ViByte writeBuffer[BUFFER_SIZE];
-
- if (fl45_invalidViBooleanRange (hold))
- return VI_ERROR_PARAMETER2;
- if (fl45_invalidViInt16Range (hold_thresh, 1, 3))
- return VI_ERROR_PARAMETER3;
-
- if (hold == 0)
- Fmt (writeBuffer, "%s<HOLDCLR");
- else
- Fmt (writeBuffer, "%s<HOLD;HOLDTHRESH %d; HOLD;",hold_thresh);
-
- if ((fl45_status = viWrite (instrSession, writeBuffer, NumFmtdBytes(), &retCnt)) < 0)
- return fl45_status;
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: Decibels */
- /* Purpose: This functions turns the DB modifier (dBm or dB power) on or */
- /* off. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_configDecibel (ViSession instrSession, ViInt16 db, ViInt16 db_ref)
- {
- ViStatus fl45_status = VI_SUCCESS;
- fl45_instrRange instrPtr;
- ViUInt32 retCnt = 0;
- ViByte writeBuffer[BUFFER_SIZE];
-
- if (fl45_invalidViInt16Range (db, 0, 2))
- return VI_ERROR_PARAMETER2;
- if (fl45_invalidViInt16Range (db_ref, 1, 21))
- return VI_ERROR_PARAMETER3;
-
- if ((fl45_status = viGetAttribute (instrSession, VI_ATTR_USER_DATA, &instrPtr)) < 0)
- return fl45_status;
-
- if (db == 0)
- Fmt (writeBuffer, "%s<%s;", decibel[db]);
- else {
- if (instrPtr -> primeDispStatus < 7)
- return VI_ERROR_CONFIGURE_ERROR;
-
- if ((db == 2) && (db_ref > 4))
- return VI_ERROR_CONFIGURE_RANGE;
-
- if (db==1)
- Fmt (writeBuffer, "%s<%s %d;", decibel[db], db_ref);
- else
- Fmt (writeBuffer, "%s<%s %d; %s;", decibel[db], db_ref, decibel[db+1]);
- }
-
- if ((fl45_status = viWrite (instrSession, writeBuffer, NumFmtdBytes(), &retCnt)) < 0)
- return fl45_status;
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: Relative */
- /* Purpose: This function turns the Relative modifier on or off. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_configRelative (ViSession instrSession, ViInt16 rel, ViReal64 base_set)
- {
- ViStatus fl45_status = VI_SUCCESS;
- ViUInt32 retCnt = 0;
- ViByte writeBuffer[BUFFER_SIZE];
-
- if (fl45_invalidViInt16Range (rel, 0, 2))
- return VI_ERROR_PARAMETER2;
- if (fl45_invalidViReal64Range (base_set, -2e7, 2e7))
- return VI_ERROR_PARAMETER3;
-
- if (rel == 2)
- Fmt(writeBuffer, "%s<%s %f;", relative[rel],base_set);
- else
- Fmt(writeBuffer, "%s<%s;", relative[rel]);
-
- if ((fl45_status = viWrite (instrSession, writeBuffer, NumFmtdBytes(), &retCnt)) < 0)
- return fl45_status;
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: Min/Max */
- /* Purpose: This function turns the MN MX modifier on or off. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_configMinMax (ViSession instrSession, ViInt16 min_max, ViReal64 min_set, ViReal64 max_set)
- {
- ViStatus fl45_status = VI_SUCCESS;
- ViUInt32 retCnt = 0;
- ViByte writeBuffer[BUFFER_SIZE];
-
- if (fl45_invalidViInt16Range (min_max, 0, 4))
- return VI_ERROR_PARAMETER2;
- if (fl45_invalidViReal64Range (min_set, -2.0e7, 2.0e7))
- return VI_ERROR_PARAMETER3;
- if (fl45_invalidViReal64Range (max_set, -2.0e7, 2.0e7))
- return VI_ERROR_PARAMETER4;
-
- if (min_max == 2)
- Fmt(writeBuffer, "%s<%s %f;",minMaxSet[min_max], min_set);
- else if (min_max == 4)
- Fmt(writeBuffer, "%s<%s %f;",minMaxSet[min_max], max_set);
- else
- Fmt(writeBuffer, "%s<%s;", minMaxSet[min_max]);
-
- if ((fl45_status = viWrite (instrSession, writeBuffer, NumFmtdBytes(), &retCnt)) < 0)
- return fl45_status;
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: Trigger */
- /* Purpose: The trigger function executes a trigger. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_trigger (ViSession instrSession)
- {
- ViStatus fl45_status = VI_SUCCESS;
- fl45_instrRange instrPtr;
- ViUInt32 retCnt = 0;
-
- if ((fl45_status = viGetAttribute (instrSession, VI_ATTR_USER_DATA, &instrPtr)) < 0)
- return fl45_status;
-
- if (instrPtr -> trigStatus > 1)
- if ((fl45_status = viWrite (instrSession, "*TRG;", 5, &retCnt)) < 0)
- return fl45_status;
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: fl45_Compare */
- /* Purpose: The Compare function when executed will display if the */
- /* measurement is within the values defined in the */
- /* fl45_Config_compare. The function checks to see if the */
- /* Compare function has been executed. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_measCompare (ViSession instrSession, ViPChar charOutput, ViPInt16 intOutput)
- {
- ViStatus fl45_status = VI_SUCCESS;
- ViUInt32 retCnt = 0;
- ViUInt16 n = 0;
- ViByte rdBuffer[BUFFER_SIZE];
-
- FillBytes (charOutput, 0, 8, 0);
-
- if ((fl45_status = viWrite (instrSession, "MOD?", 4, &retCnt)) < 0)
- return fl45_status;
- if ((fl45_status = viScanf (instrSession, "%hd", &n)) < 0)
- return fl45_status;
-
- if ((n & 64) != 64)
- return VI_ERROR_CONFIGURE_COMPARE;
-
- if ((fl45_status = viWrite (instrSession, "COMP?", 5, &retCnt)) < 0)
- return fl45_status;
- if ((fl45_status = viRead (instrSession, rdBuffer, BUFFER_SIZE, &retCnt)) < 0)
- return fl45_status;
- if (Scan (rdBuffer, "%s>%s[xt10]", charOutput) != 1)
- return VI_ERROR_INTERPRETING_RESPONSE;
-
- switch (charOutput[0]) {
- case 'H': *intOutput = 1;
- break;
- case 'P': *intOutput = 0;
- break;
- case 'L': *intOutput = -1;
- break;
- default : *intOutput = -999;
- break;
- }
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: Primary Display */
- /* Purpose: This function reads the data from the Primary Display. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_measPrimDisp (ViSession instrSession, ViBoolean wait, ViPReal64 ch_1)
- {
- ViStatus fl45_status = VI_SUCCESS;
- fl45_instrRange instrPtr;
- ViUInt32 retCnt = 0;
- ViUInt16 status = 0, done = 0;
-
- if (fl45_invalidViBooleanRange (wait))
- return VI_ERROR_PARAMETER2;
-
- if ((fl45_status = viGetAttribute (instrSession, VI_ATTR_USER_DATA, &instrPtr)) < 0)
- return fl45_status;
-
- if (instrPtr -> trigStatus > 1) {
- if (wait == 0) {
- if ((fl45_status = viWrite (instrSession, "VAL1?", 5, &retCnt)) < 0)
- return fl45_status;
- }
- else {
- if ((fl45_status = viWrite (instrSession, "MEAS1?", 6, &retCnt)) < 0)
- return fl45_status;
- done = 0;
- while (!done) {
- if ((fl45_status = viReadSTB (instrSession, &status)) < 0)
- return fl45_status;
- if ((status & 0x10) == 0x10)
- done = 1;
- if (fl45_status != VI_SUCCESS)
- return fl45_status;
- }
- }
- }
- else
- if ((fl45_status = viWrite (instrSession, "VAL1?", 5, &retCnt)) < 0)
- return fl45_status;
-
- if ((fl45_status = viScanf (instrSession, "%lf", ch_1)) < 0)
- return fl45_status;
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*=========================================================================*/
- /* Function: Secondary Display */
- /* Purpose: This function reads the data from the Secondary Display. */
- /*=========================================================================*/
- ViStatus _VI_FUNC fl45_measSecDisp (ViSession instrSession, ViBoolean wait, ViPReal64 ch_2)
- {
- ViStatus fl45_status = VI_SUCCESS;
- fl45_instrRange instrPtr;
- ViUInt32 retCnt = 0;
- ViUInt16 status = 0, done = 0;
-
- if (fl45_invalidViBooleanRange (wait))
- return VI_ERROR_PARAMETER2;
-
- if ((fl45_status = viGetAttribute (instrSession, VI_ATTR_USER_DATA, &instrPtr)) < 0)
- return fl45_status;
-
- if (instrPtr -> trigStatus > 1) {
- if (wait == 0) {
- if ((fl45_status = viWrite (instrSession, "VAL2?", 5, &retCnt)) < 0)
- return fl45_status;
- }
- else {
- if ((fl45_status = viWrite (instrSession, "MEAS2?", 6, &retCnt)) < 0)
- return fl45_status;
- done = 0;
- while (!done) {
- if ((fl45_status = viReadSTB (instrSession, &status)) < 0)
- return fl45_status;
- if ((status & 0x10) == 0x10)
- done = 1;
- if (fl45_status != VI_SUCCESS)
- return fl45_status;
- }
- }
- }
- else
- if ((fl45_status = viWrite (instrSession, "VAL2?", 5, &retCnt)) < 0)
- return fl45_status;
-
- if ((fl45_status = viScanf (instrSession, "%lf", ch_2)) < 0)
- return fl45_status;
-
- fl45_status = fl45_instrStatus (instrSession);
- return fl45_status;
- }
-
- /*****************************************************************************/
- /*-------- INSERT USER-CALLABLE INSTRUMENT-DEPENDENT ROUTINES HERE ----------*/
- /*****************************************************************************/
-
- /*===========================================================================*/
- /* Function: Write To Instrument */
- /* Purpose: This function writes a command string to the instrument. */
- /*===========================================================================*/
- ViStatus _VI_FUNC fl45_writeInstrData (ViSession instrSession, ViString writeBuffer)
- {
- ViStatus fl45_status = VI_SUCCESS;
-
- if ((fl45_status = viPrintf (instrSession, "%s", writeBuffer)) < 0)
- return fl45_status;
-
- return fl45_status;
- }
-
- /*===========================================================================*/
- /* Function: Read Instrument Buffer */
- /* Purpose: This function reads the output buffer of the instrument. */
- /*===========================================================================*/
- ViStatus _VI_FUNC fl45_readInstrData (ViSession instrSession, ViInt16 numBytes,
- ViChar rdBuf[], ViPInt32 bytesRead)
- {
- ViStatus fl45_status = VI_SUCCESS;
- *bytesRead = 0L;
-
- if ((fl45_status = viRead (instrSession, rdBuf, numBytes, bytesRead)) < 0)
- return fl45_status;
-
- return fl45_status;
- }
-
- /*===========================================================================*/
- /* Function: Reset */
- /* Purpose: This function resets the instrument. If the reset function */
- /* is not supported by the instrument, this function returns */
- /* the warning VI_WARN_NSUP_RESET. */
- /*===========================================================================*/
- ViStatus _VI_FUNC fl45_reset (ViSession instrSession)
- {
- ViUInt32 retCnt = 0;
- ViStatus fl45_status = VI_SUCCESS;
-
- /* Initialize the instrument to a known state. */
- if ((fl45_status = viWrite (instrSession, "*RST", 4, &retCnt)) < 0)
- return fl45_status;
-
- if ((fl45_status = fl45_defaultInstrSetup (instrSession)) < 0)
- return fl45_status;
-
- return fl45_status;
- }
-
- /*===========================================================================*/
- /* Function: Self-Test */
- /* Purpose: This function executes the instrument self-test and returns */
- /* the result. If the self test function is not supported by the */
- /* instrument, this function returns the warning */
- /* VI_WARN_NSUP_SELF_TEST. */
- /*===========================================================================*/
- ViStatus _VI_FUNC fl45_selfTest (ViSession instrSession, ViPInt16 testResult,
- ViChar testMessage[])
- {
- ViUInt16 status = 0, done = 0;
- ViUInt32 retCnt = 0;
- ViStatus fl45_status = VI_SUCCESS;
-
- if ((fl45_status = viWrite (instrSession, "*TST?", 5, &retCnt)) < 0)
- return fl45_status;
-
- done = 0;
- while (done == 0) {
- fl45_status = viReadSTB (instrSession, &status);
- if ((status & 0x10) == 0x10)
- done = 1;
- if (fl45_status != VI_SUCCESS)
- return fl45_status;
- }
-
- if ((fl45_status = viScanf (instrSession, "%hd", testResult)) < 0)
- return fl45_status;
- if (Scan (testResult, "%d[b2]>%s", testMessage) != 1)
- fl45_status = VI_ERROR_INTERPRETING_RESPONSE;
-
- return fl45_status;
- }
-
- /*===========================================================================*/
- /* Function: Error Query */
- /* Purpose: This function queries the instrument error queue, and returns */
- /* the result. If the error query function is not supported by the */
- /* instrument, this function returns the warning */
- /* VI_WARN_NSUP_ERROR_QUERY. */
- /*===========================================================================*/
- ViStatus _VI_FUNC fl45_errorQuery (ViSession instrSession, ViPInt32 errCode,
- ViChar errMessage[])
- {
- ViUInt32 retCnt = 0;
- ViStatus fl45_status = VI_SUCCESS;
-
- fl45_status = VI_WARN_NSUP_ERROR_QUERY;
-
- return fl45_status;
- }
-
- /*===========================================================================*/
- /* Function: Error Message */
- /* Purpose: This function translates the error return value from the */
- /* instrument driver into a user-readable string. */
- /*===========================================================================*/
- ViStatus _VI_FUNC fl45_errorMessage (ViSession instrSession, ViStatus errorCode,
- ViChar errMessage[])
- {
- ViStatus fl45_status = VI_SUCCESS;
- ViInt16 i;
- static fl45_tStringValPair statusDescArray[] = {
- {VI_WARN_NSUP_ID_QUERY, "WARNING: ID Query not supported"},
- {VI_WARN_NSUP_RESET, "WARNING: Reset not supported"},
- {VI_WARN_NSUP_SELF_TEST, "WARNING: Self-test not supported"},
- {VI_WARN_NSUP_ERROR_QUERY, "WARNING: Error Query not supported"},
- {VI_WARN_NSUP_REV_QUERY, "WARNING: Revision Query not supported"},
- {VI_ERROR_PARAMETER1, "ERROR: Parameter 1 out of range"},
- {VI_ERROR_PARAMETER2, "ERROR: Parameter 2 out of range"},
- {VI_ERROR_PARAMETER3, "ERROR: Parameter 3 out of range"},
- {VI_ERROR_PARAMETER4, "ERROR: Parameter 4 out of range"},
- {VI_ERROR_PARAMETER5, "ERROR: Parameter 5 out of range"},
- {VI_ERROR_PARAMETER6, "ERROR: Parameter 6 out of range"},
- {VI_ERROR_PARAMETER7, "ERROR: Parameter 7 out of range"},
- {VI_ERROR_PARAMETER8, "ERROR: Parameter 8 out of range"},
- {VI_ERROR_FAIL_ID_QUERY,"ERROR: Identification query failed"},
- {VI_ERROR_INV_RESPONSE, "ERROR: Interpreting instrument response"},
- {VI_ERROR_FILE_OPEN, "ERROR: Opening the specified file"},
- {VI_ERROR_FILE_WRITE, "ERROR: Writing to the specified file"},
- {VI_ERROR_INTERPRETING_RESPONSE, "ERROR: Interpreting the instrument's response"},
-
- /*=CHANGE:=============================================================*/
- /* Insert instrument-specific error codes here. Example: */
- /* */
- /* {INSTRUMENT_SPECIFIC_ERROR, "ERROR: Instrument specific error"}, */
- /* */
- /*=====================================================================*/
-
- {VI_NULL, VI_NULL}
- };
-
- fl45_status = viStatusDesc (instrSession, errorCode, errMessage);
- if (fl45_status == VI_WARN_UNKNOWN_STATUS) {
- for (i=0; statusDescArray[i].stringName; i++) {
- if (statusDescArray[i].stringVal == errorCode) {
- strcpy (errMessage, statusDescArray[i].stringName);
- return (VI_SUCCESS);
- }
- }
- sprintf (errMessage, "Unknown Error 0x%08lX", errorCode);
- return (VI_WARN_UNKNOWN_STATUS);
- }
-
- fl45_status = VI_SUCCESS;
- return fl45_status;
- }
-
- /*===========================================================================*/
- /* Function: Revision Query */
- /* Purpose: This function returns the driver and instrument revisions. */
- /* If the revision query function is not supported by the */
- /* instrument, this function returns the warning */
- /* VI_WARN_NSUP_REV_QUERY. */
- /*===========================================================================*/
- ViStatus _VI_FUNC fl45_revisionQuery (ViSession instrSession,
- ViChar driverRev[], ViChar instrRev[])
- {
- ViUInt32 retCnt = 0;
- fl45_instrRange instrPtr;
- ViStatus fl45_status = VI_SUCCESS;
-
- if ((fl45_status = viGetAttribute (instrSession, VI_ATTR_USER_DATA, &instrPtr)) < 0)
- return fl45_status;
-
- if ((fl45_status = viWrite (instrSession, "*IDN?", 5, &retCnt)) < 0)
- return fl45_status;
-
- if ((fl45_status = viScanf (instrSession, "%*[^,],%*[^,],%*[^,], %[^\n]", instrRev)) < 0)
- return fl45_status;
-
- strcpy (driverRev, instrPtr -> instrDriverRevision);
-
- return fl45_status;
- }
-
- /*===========================================================================*/
- /* Function: Close */
- /* Purpose: This function closes the instrument. */
- /*===========================================================================*/
- ViStatus _VI_FUNC fl45_close (ViSession instrSession)
- {
- fl45_instrRange instrPtr;
- ViSession rmSession;
- ViStatus fl45_status = VI_SUCCESS;
-
- if ((fl45_status = viGetAttribute (instrSession, VI_ATTR_RM_SESSION, &rmSession)) < 0)
- return fl45_status;
- if ((fl45_status = viGetAttribute (instrSession, VI_ATTR_USER_DATA, &instrPtr)) < 0)
- return fl45_status;
-
- free (instrPtr);
-
- fl45_status = viClose (instrSession);
- viClose (rmSession);
-
- return fl45_status;
- }
-
- /*****************************************************************************/
- /*= UTILITY ROUTINES (Non-Exportable Functions) =============================*/
- /*****************************************************************************/
-
- /*===========================================================================*/
- /* Function: Boolean Value Out Of Range - ViBoolean */
- /* Purpose: This function checks a Boolean to see if it is equal to VI_TRUE */
- /* or VI_FALSE. If the value is out of range, the return value is */
- /* VI_TRUE, otherwise the return value is VI_FALSE. */
- /*===========================================================================*/
- ViBoolean fl45_invalidViBooleanRange (ViBoolean val)
- {
- return ((val != VI_FALSE && val != VI_TRUE) ? VI_TRUE : VI_FALSE);
- }
-
- /*===========================================================================*/
- /* Function: Short Signed Integer Value Out Of Range - ViInt16 */
- /* Purpose: This function checks a short signed integer value to see if it */
- /* lies between a minimum and maximum value. If the value is out */
- /* of range, the return value is VI_TRUE, otherwise the return */
- /* value is VI_FALSE. */
- /*===========================================================================*/
- ViBoolean fl45_invalidViInt16Range (ViInt16 val, ViInt16 min, ViInt16 max)
- {
- return ((val < min || val > max) ? VI_TRUE : VI_FALSE);
- }
-
- /*===========================================================================*/
- /* Function: Long Signed Integer Value Out Of Range - ViInt32 */
- /* Purpose: This function checks a long signed integer value to see if it */
- /* lies between a minimum and maximum value. If the value is out */
- /* of range, the return value is VI_TRUE, otherwise the return */
- /* value is VI_FALSE. */
- /*===========================================================================*/
- ViBoolean fl45_invalidViInt32Range (ViInt32 val, ViInt32 min, ViInt32 max)
- {
- return ((val < min || val > max) ? VI_TRUE : VI_FALSE);
- }
-
- /*===========================================================================*/
- /* Function: Short Unsigned Integer Value Out Of Range - ViUInt16 */
- /* Purpose: This function checks a short unsigned integer value to see if it*/
- /* lies between a minimum and maximum value. If the value is out */
- /* of range, the return value is VI_TRUE, otherwise the return */
- /* value is VI_FALSE. */
- /*===========================================================================*/
- ViBoolean fl45_invalidViUInt16Range (ViUInt16 val, ViUInt16 min, ViUInt16 max)
- {
- return ((val < min || val > max) ? VI_TRUE : VI_FALSE);
- }
-
- /*===========================================================================*/
- /* Function: Long Unsigned Integer Value Out Of Range - ViUInt32 */
- /* Purpose: This function checks a long unsigned integer value to see if it */
- /* lies between a minimum and maximum value. If the value is out */
- /* of range, the return value is VI_TRUE, otherwise the return */
- /* value is VI_FALSE. */
- /*===========================================================================*/
- ViBoolean fl45_invalidViUInt32Range (ViUInt32 val, ViUInt32 min, ViUInt32 max)
- {
- return ((val < min || val > max) ? VI_TRUE : VI_FALSE);
- }
-
- /*===========================================================================*/
- /* Function: Real (Float) Value Out Of Range - ViReal32 */
- /* Purpose: This function checks a real (float) value to see if it lies */
- /* between a minimum and maximum value. If the value is out of */
- /* range, the return value is VI_TRUE, otherwise the return value */
- /* is VI_FALSE. */
- /*===========================================================================*/
- ViBoolean fl45_invalidViReal32Range (ViReal32 val, ViReal32 min, ViReal32 max)
- {
- return ((val < min || val > max) ? VI_TRUE : VI_FALSE);
- }
-
- /*===========================================================================*/
- /* Function: Real (Double) Value Out Of Range - ViReal64 */
- /* Purpose: This function checks a real (double) value to see if it lies */
- /* between a minimum and maximum value. If the value is out of */
- /* range, the return value is VI_TRUE, otherwise the return value */
- /* is VI_FALSE. */
- /*===========================================================================*/
- ViBoolean fl45_invalidViReal64Range (ViReal64 val, ViReal64 min, ViReal64 max)
- {
- return ((val < min || val > max) ? VI_TRUE : VI_FALSE);
- }
-
- /*===========================================================================*/
- /* Function: Initialize Clean Up */
- /* Purpose: This function is used only by the fl45_init function. When */
- /* an error is detected this function is called to close the */
- /* open resource manager and instrument object sessions and to */
- /* set the instrSession that is returned from fl45_init to */
- /* VI_NULL. */
- /*===========================================================================*/
- ViStatus fl45_initCleanUp (ViSession openRMSession,
- ViPSession openInstrSession, ViStatus currentStatus)
- {
- viClose (*openInstrSession);
- viClose (openRMSession);
- *openInstrSession = VI_NULL;
-
- return currentStatus;
- }
-
- /*===========================================================================*/
- /* Function: Read To File From Instrument */
- /* Purpose: This function is used to read data from the instrument and */
- /* write it to a user specified file. */
- /*===========================================================================*/
- ViStatus fl45_readToFile (ViSession instrSession, ViString filename,
- ViUInt32 readBytes, ViPUInt32 retCount)
- {
- ViStatus fl45_status = VI_SUCCESS;
- ViByte buffer[BUFFER_SIZE];
- ViUInt32 bytesReadInstr = 0, bytesWrittenFile = 0;
- FILE *targetFile;
-
- *retCount = 0L;
- if ((targetFile = fopen (filename, "wb")) == VI_NULL)
- return VI_ERROR_FILE_OPEN; /* not defined by VTL */
-
- for (;;) {
- if (readBytes > BUFFER_SIZE)
- fl45_status = viRead (instrSession, buffer, BUFFER_SIZE, &bytesReadInstr);
- else
- fl45_status = viRead (instrSession, buffer, readBytes, &bytesReadInstr);
-
- bytesWrittenFile = fwrite (buffer, sizeof (ViByte), (size_t)bytesReadInstr, targetFile);
- *retCount += bytesWrittenFile;
- if (bytesWrittenFile < bytesReadInstr)
- fl45_status = VI_ERROR_FILE_WRITE; /* not defined by VTL */
-
- if ((readBytes <= BUFFER_SIZE) || (fl45_status <= 0) || (fl45_status == VI_SUCCESS_TERM_CHAR))
- break;
-
- readBytes -= BUFFER_SIZE;
- }
-
- fclose (targetFile);
- return fl45_status;
- }
-
- /*===========================================================================*/
- /* Function: Write From File To Instrument */
- /* Purpose: This function is used to read data from a user specified file */
- /* and write it to the instrument. */
- /*===========================================================================*/
- ViStatus fl45_writeFromFile (ViSession instrSession, ViString filename,
- ViUInt32 writeBytes, ViPUInt32 retCount)
- {
- ViStatus fl45_status = VI_SUCCESS;
- ViByte buffer[BUFFER_SIZE];
- ViUInt32 bytesRead = 0, bytesWritten = 0;
- FILE *sourceFile;
- ViBoolean sendEnd = VI_FALSE;
-
- *retCount = 0L;
- if ((sourceFile = fopen (filename, "rb")) == VI_NULL)
- return VI_ERROR_FILE_OPEN; /* not defined by VTL */
-
- while (!feof (sourceFile)) {
- bytesRead = (ViUInt32)fread (buffer, sizeof (ViByte), BUFFER_SIZE, sourceFile);
- if ((writeBytes > BUFFER_SIZE) && (bytesRead == BUFFER_SIZE)) {
- viGetAttribute (instrSession, VI_ATTR_SEND_END_EN, &sendEnd);
- viSetAttribute (instrSession, VI_ATTR_SEND_END_EN, VI_FALSE);
- fl45_status = viWrite (instrSession, buffer, BUFFER_SIZE, &bytesWritten);
- viSetAttribute (instrSession, VI_ATTR_SEND_END_EN, sendEnd);
- writeBytes -= BUFFER_SIZE;
- *retCount += bytesWritten;
- if (fl45_status < 0)
- break;
- }
- else {
- fl45_status = viWrite (instrSession, buffer, ((bytesRead < writeBytes) ? bytesRead : writeBytes), &bytesWritten);
- *retCount += bytesWritten;
- break;
- }
- }
-
- fclose (sourceFile);
- return fl45_status;
- }
-
- /*===========================================================================*/
- /* Function: Status */
- /* Purpose: This function checks the event status register. */
- /*===========================================================================*/
- ViStatus fl45_instrStatus (ViSession instrSession)
- {
- ViStatus fl45_status = VI_SUCCESS;
- ViUInt32 retCnt = 0;
- ViInt16 esr = 0;
-
- if ((fl45_status = viWrite (instrSession, "*ESR?;", 6, &retCnt)) < 0)
- return fl45_status;
-
- if ((fl45_status = viScanf (instrSession, "%hd", &esr)) < 0)
- return fl45_status;
-
- if ((esr & 0x10) == 0x10)
- fl45_status = VI_ERROR_INSTRUMENT_ERROR;
- else
- fl45_status = VI_SUCCESS;
-
- return fl45_status;
- }
-
- /*****************************************************************************/
- /*----------- INSERT INSTRUMENT-DEPENDENT UTILITY ROUTINES HERE -------------*/
- /*****************************************************************************/
-
- /*===========================================================================*/
- /* Function: Default Instrument Setup */
- /* Purpose: This function sends a default setup to the instrument. This */
- /* function is called by the fl45_reset operation and by the */
- /* fl45_init function if the reset option has not been selected. */
- /* This function is useful for configuring any instrument settings */
- /* that are required by the rest of the instrument driver */
- /* functions such as turning headers ON or OFF or using the long */
- /* or short form for commands, queries, and data. */
- /*===========================================================================*/
- ViStatus fl45_defaultInstrSetup (ViSession instrSession)
- {
- ViStatus fl45_status = VI_SUCCESS;
- ViUInt32 retCnt = 0;
- fl45_instrRange instrPtr;
-
- instrPtr = malloc (sizeof (struct fl45_statusDataRanges));
-
- instrPtr -> primeDispStatus = 9;
- instrPtr -> secDispStatus = 0;
- instrPtr -> trigStatus = 1;
- strcpy (instrPtr -> instrDriverRevision, fl45_REVISION);
-
- if (viSetAttribute (instrSession, VI_ATTR_USER_DATA, (ViUInt32)instrPtr) != 0)
- return fl45_status;
-
- if ((fl45_status = viWrite (instrSession, "*CLS;*ESE 63", 12, &retCnt)) < 0)
- return fl45_status;
-
- return fl45_status;
- }
-
- /*****************************************************************************/
- /*=== END INSTRUMENT DRIVER SOURCE CODE =====================================*/
- /*****************************************************************************/
-