home *** CD-ROM | disk | FTP | other *** search
-
- #include <visa.h>
- #include <ansi_c.h>
- #include <string.h>
- #include <formatio.h>
- #include "hp5313xA.h"
-
- #define hp5313xa_REVISION "Rev 1.0, 9/95, CVI 3.1" /* Instrument driver revision */
- #define BUFFER_SIZE 512L /* File I/O buffer size */
-
- /*= HP 53131A/132A Univeral Counter ===================================================*/
- /* LabWindows/CVI 3.1 Instrument Driver */
- /* Original Release: January 1994 */
- /* By: DT LWILDP, National Instruments, Austin, Texas. */
- /* PH. (800)433-3488 Fax (512)794-5678 */
- /* Originally written in C */
- /* */
- /* Modification History: */
- /* */
- /* June 1995 - Modified the LabWindows/CVI instrument driver to use */
- /* VISA I/O calls. */
- /* */
- /* Modified by: CSC, National Instruments, Austin, Texas */
- /* */
- /*===========================================================================*/
-
- /*****************************************************************************/
- /*= INSTRUMENT-DEPENDENT COMMAND ARRAYS =====================================*/
- /*****************************************************************************/
- static ViString model[3] = {"", "HEWLETT-PACKARD,53131A", "HEWLETT-PACKARD,53132A"};
- static ViInt16 atten[2] = {1,10};
- static ViString coupl[2] = {"ac","dc"};
- static ViString impeda[2] = {"50", "1E6"};
- static ViString switchs[2] = {"off", "on"};
- static ViInt16 hyster[3] = {0,50,100};
- static ViString slope[2] = {"neg","pos"};
- static ViString lmShow[2] = {"numb","grap"};
- static ViString frp[7] = {"","freq 1","freq 2","freq 3","freq:rat 1,2","freq:rat 1,3","per 1"};
- static ViString stopcom[4] = {"ext","ext","tim","imm"};
- static ViString twd[5] = {"rise:time","fall:time","pwid","nwid","dcyc"};
- static ViString common[2] = {"inp2","inp1"};
- static ViString mathShow[5] = {"","sdev","mean","max","min"};
- static ViString exeMode[4] = {":init",":init:cont on","init:cont off","abor"};
- static ViString configFunc[23] = {"dcyc 50","fall:time 10,90","rise:time 10,90",
- "freq (@1)","freq (@2)","freq (@3)",
- "freq:rat (@1),(@2)","freq:rat (@1),(@3)",
- "max (@1)","min (@1)",
- "max (@2)","min (@2)",
- "nwid 50,(@1)","pwid 50,(@1)",
- "per (@1)","per (@2)","per (@3)",
- "phas (@1),(@2)","ptp (@1)","ptp (@2)",
- "tint (@1),(@2)","tot:cont (@1)","tot:tim (@1)"};
- static ViString postProcs[3] = {":calc2:imm","calc2:imm:auto on",":calc2:imm:auto off"};
- static ViString measFunc[20] = { "dcyc? 50","fall:time? 10,90","rise:time? 10,90",
- "freq? (@1)","freq? (@2)","freq? (@3)",
- "freq:rat? (@1),(@2)","freq:rat? (@1),(@3)",
- "max? (@1)","min? (@1)",
- "max? (@2)","min? (@2)",
- "nwid? 50,(@1)","pwid? 50,(@1)",
- "per? (@1)","per? (@2)","per? (@3)",
- "phas? (@1),(@2)","ptp? (@1)","ptp? (@2)"};
- static ViString method[3] = {"meas","read","fetch"};
-
- /*****************************************************************************/
- /*= INSTRUMENT-DEPENDENT STATUS/RANGE STRUCTURE ============================*/
- /*****************************************************************************/
- /* hp5313xa_stringValPair is used in the hp5313xa_errorMessage function */
- /* hp5313xa_statusDataRanges is used to track session dependent status & ranges*/
- /*===========================================================================*/
- typedef struct hp5313xa_stringValPair
- {
- ViStatus stringVal;
- ViString stringName;
- } hp5313xa_tStringValPair;
-
- struct hp5313xa_statusDataRanges {
- ViInt16 triggerMode;
- ViInt16 val2;
- ViInt16 val3;
- ViChar instrDriverRevision[256];
- };
-
- typedef struct hp5313xa_statusDataRanges *hp5313xa_instrRange;
-
- /*****************************************************************************/
- /*= UTILITY ROUTINE DECLARATIONS (Non-Exportable Functions) =================*/
- /*****************************************************************************/
- ViBoolean hp5313xa_invalidViBooleanRange (ViBoolean val);
- ViBoolean hp5313xa_invalidViInt16Range (ViInt16 val, ViInt16 min, ViInt16 max);
- ViBoolean hp5313xa_invalidViInt32Range (ViInt32 val, ViInt32 min, ViInt32 max);
- ViBoolean hp5313xa_invalidViUInt16Range (ViUInt16 val, ViUInt16 min, ViUInt16 max);
- ViBoolean hp5313xa_invalidViUInt32Range (ViUInt32 val, ViUInt32 min, ViUInt32 max);
- ViBoolean hp5313xa_invalidViReal32Range (ViReal32 val, ViReal32 min, ViReal32 max);
- ViBoolean hp5313xa_invalidViReal64Range (ViReal64 val, ViReal64 min, ViReal64 max);
- ViStatus hp5313xa_initCleanUp (ViSession openRMSession, ViPSession openInstrSession, ViStatus currentStatus);
- ViStatus hp5313xa_readToFile (ViSession instrSession, ViString filename, ViUInt32 readBytes, ViPUInt32 retCount);
- ViStatus hp5313xa_writeFromFile (ViSession instrSession, ViString filename, ViUInt32 writeBytes, ViPUInt32 retCount);
- ViStatus hp5313xa_get_error (ViSession instrSession);
- ViStatus hp5313xa_poll (ViSession instrSession, ViInt16 *);
- ViStatus hp5313xa_set_timeout (ViSession instrSession, ViAttrState timeOutCode);
- ViStatus hp5313xa_defaultInstrSetup (ViSession openInstrSession);
-
- /*****************************************************************************/
- /*====== 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 hp5313xa_init (ViRsrc resourceName, ViBoolean IDQuery,
- ViBoolean resetDevice, ViInt16 instrumentModel,
- ViSession *instrSession)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViSession rmSession = 0;
- ViUInt32 retCnt = 0;
- ViByte rdBuffer[BUFFER_SIZE];
-
- /*- Check input parameter ranges ----------------------------------------*/
-
- if (hp5313xa_invalidViBooleanRange (IDQuery))
- return VI_ERROR_PARAMETER2;
- if (hp5313xa_invalidViBooleanRange (resetDevice))
- return VI_ERROR_PARAMETER3;
- if (hp5313xa_invalidViInt16Range (instrumentModel, 1, 2))
- return VI_ERROR_PARAMETER4;
-
- /*- Open instrument session ---------------------------------------------*/
-
- if ((hp5313xa_status = viOpenDefaultRM (&rmSession)) < 0)
- return hp5313xa_status;
-
- if ((hp5313xa_status = viOpen (rmSession, resourceName, VI_NULL, VI_NULL, instrSession)) < 0) {
- viClose (rmSession);
- return hp5313xa_status;
- }
-
- /*- Configure VISA Formatted I/O ----------------------------------------*/
-
- if ((hp5313xa_status = viSetAttribute (*instrSession, VI_ATTR_TMO_VALUE, 10000)) < 0)
- return hp5313xa_initCleanUp (rmSession, instrSession, hp5313xa_status);
- if ((hp5313xa_status = viSetBuf (*instrSession, VI_READ_BUF|VI_WRITE_BUF, 4000)) < 0)
- return hp5313xa_initCleanUp (rmSession, instrSession, hp5313xa_status);
- if ((hp5313xa_status = viSetAttribute (*instrSession, VI_ATTR_WR_BUF_OPER_MODE,
- VI_FLUSH_ON_ACCESS)) < 0)
- return hp5313xa_initCleanUp (rmSession, instrSession, hp5313xa_status);
- if ((hp5313xa_status = viSetAttribute (*instrSession, VI_ATTR_RD_BUF_OPER_MODE,
- VI_FLUSH_ON_ACCESS)) < 0)
- return hp5313xa_initCleanUp (rmSession, instrSession, hp5313xa_status);
-
- /*- Identification Query ------------------------------------------------*/
-
- if (IDQuery) {
- if ((hp5313xa_status = viWrite (*instrSession, "*IDN?", 5, &retCnt)) < 0)
- return hp5313xa_initCleanUp (rmSession, instrSession, hp5313xa_status);
- if ((hp5313xa_status = viRead (*instrSession, rdBuffer, BUFFER_SIZE, &retCnt)) < 0)
- return hp5313xa_status;
-
- Scan (rdBuffer, model[instrumentModel]);
- if (NumFmtdBytes () != 22)
- return hp5313xa_initCleanUp (rmSession, instrSession, VI_ERROR_FAIL_ID_QUERY);
- }
-
- /*- Reset instrument ----------------------------------------------------*/
-
- if (resetDevice) {
- if ((hp5313xa_status = hp5313xa_reset (*instrSession)) < 0)
- return hp5313xa_initCleanUp (rmSession, instrSession, hp5313xa_status);
- }
- else /*- Send Default Instrument Setup ---------------------------------*/
- if ((hp5313xa_status = hp5313xa_defaultInstrSetup (*instrSession)) < 0)
- return hp5313xa_initCleanUp (rmSession, instrSession, hp5313xa_status);
-
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Input Conditions */
- /* Purpose: Controls the characteristics of the Counter's input ports */
- /* (channels 1 and 2). */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_inputCond (ViSession instrSession, ViInt16 channel,
- ViBoolean coupling, ViBoolean impedanceOhms,
- ViBoolean attenuation, ViBoolean filter)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
-
- if (hp5313xa_invalidViInt16Range (channel, 1, 2))
- return VI_ERROR_PARAMETER2;
- if (hp5313xa_invalidViBooleanRange (coupling))
- return VI_ERROR_PARAMETER3;
- if (hp5313xa_invalidViBooleanRange (impedanceOhms))
- return VI_ERROR_PARAMETER4;
- if (hp5313xa_invalidViBooleanRange (attenuation))
- return VI_ERROR_PARAMETER5;
- if (hp5313xa_invalidViBooleanRange (filter))
- return VI_ERROR_PARAMETER6;
-
- Fmt (wrtBuf, "%s<:inp%d:att %d;coup %s;imp %s;filt %s", channel, atten[attenuation],
- coupl[coupling], impeda[impedanceOhms], switchs[filter]);
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
- /*=========================================================================*/
- /* Function: Trigger & Sensitivity */
- /* Purpose: Sets the Trigger Level/Sensitivity for the selected channel. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_trigSens (ViSession instrSession, ViInt16 channel,
- ViBoolean triggerLevel, ViReal64 voltageLevel,
- ViBoolean attenuation, ViBoolean triggerSlope,
- ViInt16 sensitivity)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViInt16 total = 0;
- ViUInt32 retCnt = 0;
-
- if (hp5313xa_invalidViInt16Range (channel, 1, 2))
- return VI_ERROR_PARAMETER2;
- if (hp5313xa_invalidViBooleanRange (triggerLevel))
- return VI_ERROR_PARAMETER3;
- if (hp5313xa_invalidViBooleanRange (attenuation))
- return VI_ERROR_PARAMETER5;
- if (hp5313xa_invalidViBooleanRange (triggerSlope))
- return VI_ERROR_PARAMETER6;
- if (hp5313xa_invalidViInt16Range (sensitivity, 0, 2))
- return VI_ERROR_PARAMETER7;
-
- if (triggerLevel) {
- if (attenuation == 0) {
- if (hp5313xa_invalidViReal64Range (voltageLevel, -5.125, 5.125))
- return VI_ERROR_PARAMETER4;
- }
- else
- if (hp5313xa_invalidViReal64Range (voltageLevel, -51.25, 51.25))
- return VI_ERROR_PARAMETER4;
-
- Fmt (wrtBuf, "%s<:inp%d:att %d;:even%d:lev %f;", channel, atten[attenuation], channel
- , voltageLevel);
- }
- else {
- if (hp5313xa_invalidViInt16Range ((ViInt16) voltageLevel, 0, 100))
- return VI_ERROR_PARAMETER4;
-
- Fmt (wrtBuf, "%s<:inp%d:att %d;:even%d:lev:auto on;rel %d;", channel,
- atten[attenuation], channel, (ViInt16) voltageLevel);
- }
- total += NumFmtdBytes ();
- Fmt (wrtBuf, "%s[a]<:even%d:slop %s;hyst:rel %d;", channel, slope[triggerSlope],
- hyster[sensitivity]);
- total += NumFmtdBytes ();
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, total, &retCnt)) < 0)
- return hp5313xa_status;
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
-
- /*=========================================================================*/
- /* Function: Configure Limits */
- /* Purpose: Controls the limit test. It defines the lower and upper limit */
- /* test. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_limit (ViSession instrSession, ViBoolean limitTest,
- ViBoolean onFail, ViBoolean show, ViReal64 lowerLimit,
- ViReal64 upperLimit)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
-
- if (hp5313xa_invalidViBooleanRange (limitTest))
- return VI_ERROR_PARAMETER2;
- if (hp5313xa_invalidViBooleanRange (onFail))
- return VI_ERROR_PARAMETER3;
- if (hp5313xa_invalidViBooleanRange (show))
- return VI_ERROR_PARAMETER4;
- if (upperLimit <= lowerLimit) {
- hp5313xa_status = VI_ERROR_UPLOW_LIMIT;
- return hp5313xa_status;
- }
- if (lowerLimit != 0.0)
- if (hp5313xa_invalidViReal64Range (lowerLimit, -9.999999e+12, -1.0e-13))
- if (hp5313xa_invalidViReal64Range (lowerLimit, 1.0e-13, 9.999999e+12))
- return VI_ERROR_PARAMETER5;
- if (upperLimit != 0.0)
- if (hp5313xa_invalidViReal64Range (upperLimit, -9.999999e+12, -1.0e-13))
- if (hp5313xa_invalidViReal64Range (upperLimit, 1.0e-13, 9.999999e+12))
- return VI_ERROR_PARAMETER6;
-
- Fmt (wrtBuf, "%s<:calc2:lim:stat %s;disp %s;upp %f;low %f;:init:auto %s;",
- switchs[limitTest], lmShow[show], upperLimit, lowerLimit, switchs[onFail]);
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Configure Math */
- /* Purpose: Controls the math (scale/offset) processing. It sets the scale*/
- /* and offset values. The counter has only one fixed math */
- /* operation and is as follows: Math = "Meas" * Scale + Offset */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_math (ViSession instrSession, ViBoolean math,
- ViReal64 scaleValue, ViReal64 offsetValue)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
-
- if (hp5313xa_invalidViBooleanRange (math))
- return VI_ERROR_PARAMETER2;
- if (scaleValue != 0.0)
- if (hp5313xa_invalidViReal64Range (scaleValue, -9.999999e+12, -1.0e-13))
- if (hp5313xa_invalidViReal64Range (scaleValue, 1.0e-13, 9.999999e+12))
- return VI_ERROR_PARAMETER3;
- if (offsetValue != 0.0)
- if (hp5313xa_invalidViReal64Range (offsetValue, -9.999999e+12, -1.0e-13))
- if (hp5313xa_invalidViReal64Range (offsetValue, 1.0e-13, 9.999999e+12))
- return VI_ERROR_PARAMETER4;
-
- Fmt (wrtBuf, "%s<:trac scale, %f;:trac offset, %f;:calc:math:stat %s;",
- scaleValue, offsetValue, switchs[math]);
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Save/Recall Settings */
- /* Purpose: Saves/Recalls instrument settings to/from the specified */
- /* instrument memory location. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_savRecSet (ViSession instrSession, ViBoolean saveRecall,
- ViInt16 memoryLocation)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
-
- if (hp5313xa_invalidViBooleanRange (saveRecall))
- return VI_ERROR_PARAMETER2;
-
- if (saveRecall) {
- if (hp5313xa_invalidViInt16Range (memoryLocation, 1, 20))
- return VI_ERROR_PARAMETER3;
-
- Fmt (wrtBuf, "%s<*sav %d", memoryLocation);
- }
- else {
- if (hp5313xa_invalidViInt16Range (memoryLocation, 0, 20))
- return VI_ERROR_PARAMETER3;
-
- Fmt (wrtBuf, "%s<*rcl %d", memoryLocation);
- }
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Freq, Period, & Ratio */
- /* Purpuse: Configures the selected function for measurement.It sets the */
- /* start/stop arming sources. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_freqPeriodRatio (ViSession instrSession,
- ViInt16 selectFunction, ViInt16 selectArming,
- ViReal64 timeDigits, ViBoolean startSlope,
- ViInt16 stop)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
- ViInt16 total = 0;
-
- if (hp5313xa_invalidViInt16Range (selectFunction, 1, 6))
- return VI_ERROR_PARAMETER2;
- if (hp5313xa_invalidViInt16Range (selectArming, 0, 3))
- return VI_ERROR_PARAMETER3;
-
- Fmt (wrtBuf, "%s<:func \"%s\";", frp [selectFunction]);
- total += NumFmtdBytes();
- if (selectArming == 0) {
- Fmt (wrtBuf, "%s[a]<:freq:arm:sour imm;:freq:arm:stop:sour imm");
- total += NumFmtdBytes();
- }
- else if (selectArming == 1) {
- if (hp5313xa_invalidViInt16Range ((ViInt16)timeDigits, 3, 15))
- return VI_ERROR_PARAMETER4;
- Fmt (wrtBuf, "%s[a]<:freq:arm:sour imm;:freq:arm:stop:sour dig;dig %d",
- (ViInt16)timeDigits);
- total += NumFmtdBytes();
- }
- else if (selectArming == 2) {
- if (hp5313xa_invalidViReal64Range (timeDigits, 100e-5, 999e-5))
- if (hp5313xa_invalidViReal64Range (timeDigits, 10e-3, 1000.00))
- return VI_ERROR_PARAMETER4;
- Fmt (wrtBuf, "%s[a]<:freq:arm:sour imm;:freq:arm:stop:sour tim;tim %f",
- timeDigits);
- total += NumFmtdBytes();
- }
- if (selectArming == 3) {
- if (hp5313xa_invalidViBooleanRange (startSlope))
- return VI_ERROR_PARAMETER5;
- if (hp5313xa_invalidViInt16Range (stop, 0, 3))
- return VI_ERROR_PARAMETER6;
- Fmt (wrtBuf, "%s[a]<:freq:arm:sour ext;slop %s;stop:sour %s;",
- slope[startSlope], stopcom[stop]);
- total += NumFmtdBytes();
- if (stop == 2) {
- if (hp5313xa_invalidViReal64Range (timeDigits, 100e-5, 999e-5))
- if (hp5313xa_invalidViReal64Range (timeDigits, 10e-3, 1000.00))
- return VI_ERROR_PARAMETER4;
- Fmt (wrtBuf, "%s[a]<tim %f;", timeDigits);
- total += NumFmtdBytes();
- }
- else if (stop != 3) {
- Fmt (wrtBuf, "%s[a]<slop %s", slope[stop]);
- total += NumFmtdBytes();
- }
- }
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, total, &retCnt)) < 0)
- return hp5313xa_status;
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Phase (Ch1 To Ch2) */
- /* Purpose: Configures the Phase function for measurement.It sets the */
- /* start arming source. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_phase (ViSession instrSession, ViBoolean selectArming,
- ViBoolean startSlope)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
-
- if (hp5313xa_invalidViBooleanRange (selectArming))
- return VI_ERROR_PARAMETER2;
-
- if (selectArming == 0)
- Fmt (wrtBuf, "%s<:func \"phas\";:phas:arm:sour imm");
- else {
- if (hp5313xa_invalidViBooleanRange (startSlope))
- return VI_ERROR_PARAMETER3;
-
- Fmt (wrtBuf, "%s<:func \"phas\";:phas:arm:sour ext;slop %s", slope[startSlope]);
- }
-
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Totalize (Ch1) */
- /* Purpose: Configures the Totalize function for measurement.It sets the */
- /* start/stop arming sources. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_totalize (ViSession instrSession, ViInt16 selectArming,
- ViReal64 timeValue, ViBoolean startSlope, ViInt16 stop)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
- ViInt16 total = 0;
-
-
- if (hp5313xa_invalidViInt16Range (selectArming, 0, 2))
- return VI_ERROR_PARAMETER2;
-
- Fmt (wrtBuf, "%s<:func \"tot\";");
- total += NumFmtdBytes();
- if (selectArming == 0) {
- Fmt (wrtBuf, "%s[a]<:tot:arm:sour imm;:tot:arm:stop:sour imm");
- total += NumFmtdBytes();
- }
- else if (selectArming == 1) {
- if (hp5313xa_invalidViReal64Range (timeValue, 100e-5, 999e-5))
- if (hp5313xa_invalidViReal64Range (timeValue, 10e-3, 1000.00))
- return VI_ERROR_PARAMETER3;
- Fmt (wrtBuf, "%s[a]<:tot:arm:sour imm;:tot:arm:stop:sour tim;tim %f",
- timeValue);
- total += NumFmtdBytes();
- }
- if (selectArming == 2) {
- if (hp5313xa_invalidViBooleanRange (startSlope))
- return VI_ERROR_PARAMETER4;
- if (hp5313xa_invalidViInt16Range (stop, 0, 2))
- return VI_ERROR_PARAMETER5;
- Fmt (wrtBuf, "%s[a]<:tot:arm:sour ext;slop %s;stop:sour %s;",
- slope[startSlope], stopcom[stop]);
- total += NumFmtdBytes();
- if (stop == 2) {
- if (hp5313xa_invalidViReal64Range (timeValue, 100e-5, 999e-5))
- if (hp5313xa_invalidViReal64Range (timeValue, 10e-3, 1000.00))
- return VI_ERROR_PARAMETER3;
- Fmt (wrtBuf, "%s[a]<tim %f;", timeValue);
- total += NumFmtdBytes();
- }
- else {
- Fmt (wrtBuf, "%s[a]<slop %s", slope [stop]);
- total += NumFmtdBytes();
- }
- }
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, total, &retCnt)) < 0)
- return hp5313xa_status;
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Time, Width, Dutycycle */
- /* Purpose: Configures the selected function for measurement.It sets the */
- /* start arming source. */
- /*=========================================================================*/
-
- ViStatus _VI_FUNC hp5313xa_timWidDuty (ViSession instrSession, ViInt16 selectfunction,
- ViBoolean selectArming, ViBoolean startSlope)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
- ViInt16 total = 0;
-
- if (hp5313xa_invalidViInt16Range (selectfunction, 0, 4))
- return VI_ERROR_PARAMETER2;
- if (hp5313xa_invalidViBooleanRange (selectArming))
- return VI_ERROR_PARAMETER3;
-
- if (selectArming == 0)
- Fmt (wrtBuf, "%s<:func \"%s\";:tint:arm:sour imm", twd [selectfunction]);
- else {
- if (hp5313xa_invalidViBooleanRange (startSlope))
- return VI_ERROR_PARAMETER4;
- Fmt (wrtBuf, "%s<:func \"%s\";:tint:arm:sour ext;slop %s", twd [selectfunction],
- slope[startSlope]);
- }
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Time Interval Ch1 To Ch2 */
- /* Purpose: Configures the Time Interval function for measurement. It sets*/
- /* the start/stop arming sources. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_timeInterval (ViSession instrSession, ViBoolean startArming,
- ViBoolean startSlope, ViBoolean stop,
- ViReal64 timeValue, ViBoolean commonMode)
-
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
- ViInt16 total = 0;
-
- if (hp5313xa_invalidViBooleanRange (startArming))
- return VI_ERROR_PARAMETER2;
- if (hp5313xa_invalidViBooleanRange (stop))
- return VI_ERROR_PARAMETER4;
- if (hp5313xa_invalidViBooleanRange (commonMode))
- return VI_ERROR_PARAMETER4;
-
- Fmt (wrtBuf, "%s<:func \"tint 1,2\";:even2:feed \"%s\";", common[commonMode]);
- total += NumFmtdBytes();
- if (startArming == 0)
- Fmt (wrtBuf, "%s[a]<:tint:arm:sour imm;");
- else {
- if (hp5313xa_invalidViBooleanRange (startSlope))
- return VI_ERROR_PARAMETER3;
- Fmt (wrtBuf, "%s[a]<:tint:arm:sour ext;slop %s;", slope[startSlope]);
- }
- total += NumFmtdBytes();
-
- if (stop == 0)
- Fmt (wrtBuf, "%s[a]<stop:sour imm;");
- else {
- if (hp5313xa_invalidViReal64Range (timeValue, 100e-5, 999e-5))
- if (hp5313xa_invalidViReal64Range (timeValue, 10e-3, 1000.00))
- return VI_ERROR_PARAMETER5;
- Fmt (wrtBuf, "%s[a]<stop:sour tim;tim %f", timeValue);
- }
- total += NumFmtdBytes();
-
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, total, &retCnt)) < 0)
- return hp5313xa_status;
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Configure For Block Measurement */
- /* Purpose: Configures the counter for a block measurrement.It specifies */
- /* the number of measurements to combine for statistics */
- /* processing. It specifies which measurements will be used in */
- /* computing statistics; out-of-limit measurements can be */
- /* filtered out of the statistics processing. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_confblock (ViSession instrSession, ViBoolean statistics,
- ViInt32 ofMeasurements, ViBoolean filterData,
- ViInt16 show, ViReal64 lowerLimit, ViReal64 upperLimit)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
- ViInt16 total = 0;
-
- if (hp5313xa_invalidViBooleanRange (statistics))
- return VI_ERROR_PARAMETER2;
- if (hp5313xa_invalidViInt32Range (ofMeasurements, 2, 1000000))
- return VI_ERROR_PARAMETER3;
- if (hp5313xa_invalidViBooleanRange (filterData))
- return VI_ERROR_PARAMETER4;
- if (lowerLimit != 0.0)
- if (hp5313xa_invalidViReal64Range (lowerLimit, -9.999999e+12, -1.0e-13))
- if (hp5313xa_invalidViReal64Range (lowerLimit, 1.0e-13, 9.999999e+12))
- return VI_ERROR_PARAMETER6;
- if (upperLimit != 0.0)
- if (hp5313xa_invalidViReal64Range (upperLimit, -9.999999e+12, -1.0e-13))
- if (hp5313xa_invalidViReal64Range (upperLimit, 1.0e-13, 9.999999e+12))
- return VI_ERROR_PARAMETER7;
- if (hp5313xa_invalidViInt16Range (show, 0, 4))
- return VI_ERROR_PARAMETER5;
-
-
- Fmt (wrtBuf, "%s<:calc3:aver %s;aver:count %d[b4];:calc3:lfil:stat %s;low %f;upp %f;:trig:count:auto on;",
- switchs[statistics], ofMeasurements, switchs[filterData], lowerLimit, upperLimit);
- total += NumFmtdBytes();
- if (show == 0)
- Fmt (wrtBuf, "%s[a]<:disp:text:feed \"calc2\"");
- else
- Fmt (wrtBuf, "%s[a]<:disp:text:feed \"calc3\";:calc3:aver:type %s",
- mathShow[show]);
- total += NumFmtdBytes();
-
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, total, &retCnt)) < 0)
- return hp5313xa_status;
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Start/Stop Measurement */
- /* Purpose: Controls the initiation and termination of a measurement. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_strStpMeas (ViSession instrSession, ViInt16 executionMode)
-
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
-
- if (hp5313xa_invalidViInt16Range (executionMode, 0, 3))
- return VI_ERROR_PARAMETER2;
-
- Fmt (wrtBuf, "%s<%s", exeMode[executionMode]);
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Initiate Registers */
- /* Purpose: Clears the Standard Event Status Enable, Service Request */
- /* Enable, and presets the enable registers and transition */
- /* filters associated with the operation and questionable status */
- /* reporting structures. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_initReg (ViSession instrSession)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
-
- Fmt (wrtBuf, "%s<*cls;*sre 0;*ese 0;:stat:pres");
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Set SRQ Enable Condition */
- /* Purpose: Sets the condition at which the service request (SRQ) bit will*/
- /* be set. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_setSrqCond (ViSession instrSession, ViInt16 SRQCondition)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
-
- if (hp5313xa_invalidViInt16Range(SRQCondition, 0, 2))
- return VI_ERROR_PARAMETER2;
-
- if (SRQCondition == 0)
- Fmt (wrtBuf, "%s<*ese 1;*sre 32;*opc");
- else if (SRQCondition == 1)
- Fmt (wrtBuf, "%s<:stat:ques:enab 1024;*sre 8");
- else
- Fmt (wrtBuf, "%s<:stat:oper:enable 256;ntr 256;ptr 0;*sre 128");
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
- /*=========================================================================*/
- /* Function: Wait For SRQ */
- /* Purpose: Waits until the SRQ bit is set. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_waitSrq (ViSession instrSession)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViBoolean done;
- ViInt16 spoll;
-
- done = 0;
- while (!done) {
- if ((hp5313xa_status = viReadSTB (instrSession, &spoll)) != 0)
- return hp5313xa_status;
- if (spoll & 0x40)
- done = 1;
- }
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Configure Function */
- /* Purpose: Configures the counter for measurement of the selected */
- /* function. This function is used when "reading" or "fetching" */
- /* measurement methods are used. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_confFunc (ViSession instrSession, ViInt16 selectFunction)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
-
- if (hp5313xa_invalidViInt16Range (selectFunction, 0, 22))
- return VI_ERROR_PARAMETER2;
- Fmt (wrtBuf, ":conf:%s", configFunc[selectFunction]);
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Initiate Measurement */
- /* Purpose: Starts the measurement when the "fetching" measurement is */
- /* used. After calling this function, one can fetch for the */
- /* configured function or any related function. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_initMeas (ViSession instrSession)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViUInt32 retCnt = 0;
-
- if ((hp5313xa_status = viWrite (instrSession, ":init", 5, &retCnt)) < 0)
- return hp5313xa_status;
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Invoke Post-Processing */
- /* Purpose: Controls the post processing of data. When enabled, the */
- /* counter recalculates existing data without re-acquiring data. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_postProcess (ViSession instrSession, ViInt16 postProcess)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
-
-
- if (hp5313xa_invalidViInt16Range (postProcess, 0, 2))
- return VI_ERROR_PARAMETER2;
-
- Fmt (wrtBuf, "%s<%s", postProcs[postProcess]);
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Query Measurement */
- /* Purpose: Performs direct, read, or fetch measurement of the selected */
- /* function at the selected channel. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_queryMeas (ViSession instrSession, ViInt16 selectFunction,
- ViInt16 selectMeasMethod, ViReal64 *measuredValue)
- {
-
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViChar rdBuf[256];
- ViUInt16 response = 0;
- ViUInt32 retCnt = 0;
-
- if (hp5313xa_invalidViInt16Range (selectFunction, 0, 21))
- return VI_ERROR_PARAMETER2;
- if (hp5313xa_invalidViInt16Range (selectMeasMethod, 0, 2))
- return VI_ERROR_PARAMETER3;
- if (selectMeasMethod == 0)
- Fmt (wrtBuf, "%s<:%s:%s", method[selectMeasMethod], measFunc[selectFunction]);
- else
- Fmt (wrtBuf, "%s<:%s:%s[t32]", method[selectMeasMethod], measFunc[selectFunction]);
-
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
- do {
- if ((hp5313xa_status = viReadSTB (instrSession, &response)) != 0)
- return hp5313xa_status;
- } while (!(response & 0x10));
-
- if ((hp5313xa_status = viRead (instrSession, rdBuf, 50, &retCnt)) < 0)
- return hp5313xa_status;
- if (Scan (rdBuf, "%s>%f", measuredValue) != 1) {
- hp5313xa_status = VI_ERROR_INTERPRETING_RESPONSE;
- return hp5313xa_status;
- }
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Data Results */
- /* Purpose: Returns the data displayed on the instrument's front panel. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_dataRes (ViSession instrSession, ViReal64 *measuredData)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar rdBuf[256];
- ViUInt32 retCnt = 0;
-
-
- if ((hp5313xa_status = viWrite (instrSession, ":data?", 6, &retCnt)) < 0)
- return hp5313xa_status;
- if ((hp5313xa_status = viRead (instrSession, rdBuf, 50, &retCnt)) < 0)
- return hp5313xa_status;
-
- if (Scan (rdBuf, "%s>%f", measuredData) != 1) {
- hp5313xa_status = VI_ERROR_INTERPRETING_RESPONSE;
- return hp5313xa_status;
- }
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Math Results */
- /* Purpose: Returns the current scaled and offset measurement result. The */
- /* counter has only one fixed math operation and is as follows: */
- /* Math = "Meas" * Scale + Offset */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_mathRes (ViSession instrSession, ViReal64 *scaledOffsetData)
-
- {
-
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar rdBuf[256];
- ViUInt32 retCnt = 0;
-
- if ((hp5313xa_status = viWrite (instrSession, ":calc1:data?", 12, &retCnt)) < 0)
- return hp5313xa_status;
- if ((hp5313xa_status = viRead (instrSession, rdBuf, 50, &retCnt)) < 0)
- return hp5313xa_status;
-
- if (Scan (rdBuf, "%s>%f", scaledOffsetData) != 1) {
- hp5313xa_status = VI_ERROR_INTERPRETING_RESPONSE;
- return hp5313xa_status;
- }
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Limit Results */
- /* Purpose: Reports the results of the limit test on a multiple of */
- /* measurements. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_limitRes (ViSession instrSession, ViInt16 *dataWithinLimit,
- ViInt16 *failCount, ViInt16 *passCount,
- ViInt16 *lowerFailures, ViInt16 *upperFailures)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256] = "", rdBuf[256] = "";
- ViUInt16 response = 0;
- ViUInt32 retCnt = 0;
-
- Fmt (wrtBuf, "%s<:calc2:lim:fail?;:calc2:lim:fco?;fco:low?;upp?;:calc2:lim:pco?");
-
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
- do {
- if ((hp5313xa_status = viReadSTB (instrSession, &response)) != 0)
- return hp5313xa_status;
- } while (!(response & 0x10));
-
- if ((hp5313xa_status = viRead (instrSession, rdBuf, 50, &retCnt)) < 0)
- return hp5313xa_status;
-
-
- if (Scan (rdBuf, "%s>%d[b2];%d[b2];%d[b2];%d[b2];%d[b2]", dataWithinLimit, failCount, lowerFailures,
- upperFailures, passCount) != 5) {
- hp5313xa_status = VI_ERROR_INTERPRETING_RESPONSE;
- return hp5313xa_status;
- }
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Statistics Results */
- /* Purpose: Reports the statistical results of a block of measurements. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_statisticsRes (ViSession instrSession, ViReal64 *mean,
- ViReal64 *stdDeviation, ViReal64 *maximum,
- ViReal64 *minimum)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViChar rdBuf[256];
- ViUInt32 retCnt = 0;
-
- Fmt (wrtBuf, "%s<:calc3:aver:all?");
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
- if ((hp5313xa_status = viRead (instrSession, rdBuf, 200, &retCnt)) < 0)
- return hp5313xa_status;
-
- if (Scan (rdBuf, "%s>%f,%f,%f,%f", mean, stdDeviation, minimum, maximum) != 4) {
- hp5313xa_status = VI_ERROR_INTERPRETING_RESPONSE;
- return hp5313xa_status;
- }
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Query Chan 3's Settings */
- /* Purpose: Queries the input channel for its input conditions (coupling &*/
- /* Impedance). */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_queryChan3 (ViSession instrSession, ViBoolean *inputCoupling,
- ViBoolean *inputImpedance)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViChar rdBuf[256];
- ViUInt32 retCnt = 0;
-
- Fmt (wrtBuf, "%s<:inp3:coup?;:inp3:imp?");
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
- if ((hp5313xa_status = viRead (instrSession, rdBuf, 200, &retCnt)) < 0)
- return hp5313xa_status;
-
- if (rdBuf[0] == 'a' || rdBuf[0] == 'A')
- *inputCoupling = 1;
- else
- *inputImpedance = 0;
- if (rdBuf[4] == '5')
- *inputImpedance = 1;
- else
- *inputImpedance = 0;
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Enable/Disable Settings */
- /* Purpose: Enables or disables some major counter settings such as limit */
- /* testing, math, filtering data, and statistics. */
- /*=========================================================================*/
- ViStatus _VI_FUNC hp5313xa_enaDisSet (ViSession instrSession, ViBoolean limitTest,
- ViBoolean math, ViBoolean filterData,
- ViBoolean statistics)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
-
- if (hp5313xa_invalidViBooleanRange (limitTest))
- return VI_ERROR_PARAMETER2;
- if (hp5313xa_invalidViBooleanRange (math))
- return VI_ERROR_PARAMETER3;
- if (hp5313xa_invalidViBooleanRange (filterData))
- return VI_ERROR_PARAMETER4;
- if (hp5313xa_invalidViBooleanRange (statistics))
- return VI_ERROR_PARAMETER5;
-
- Fmt (wrtBuf, "%s<:calc3:aver %s;:calc3:lfil:stat %s;:calc:math:stat %s;:calc2:lim:stat %s",
- switchs[statistics], switchs[filterData], switchs[math], switchs[limitTest]);
- if ((hp5313xa_status = viWrite (instrSession, wrtBuf, NumFmtdBytes(), &retCnt)) < 0)
- return hp5313xa_status;
-
- if (hp5313xa_get_error (instrSession) != 0)
- return hp5313xa_status;
-
- return hp5313xa_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 hp5313xa_writeInstrData (ViSession instrSession, ViString writeBuffer)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
-
- if ((hp5313xa_status = viPrintf (instrSession, "%s", writeBuffer)) < 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*===========================================================================*/
- /* Function: Read Instrument Buffer */
- /* Purpose: This function reads the output buffer of the instrument. */
- /*===========================================================================*/
- ViStatus _VI_FUNC hp5313xa_readInstrData (ViSession instrSession, ViInt16 numBytes,
- ViChar _VI_FAR rdBuf[], ViPInt32 bytesRead)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- *bytesRead = 0L;
-
- if ((hp5313xa_status = viRead (instrSession, rdBuf, numBytes, bytesRead)) < 0)
- return hp5313xa_status;
-
- return hp5313xa_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 hp5313xa_reset (ViSession instrSession)
- {
- ViUInt32 retCnt = 0;
- ViStatus hp5313xa_status = VI_SUCCESS;
-
- /* Initialize the instrument to a known state. */
- if ((hp5313xa_status = viWrite (instrSession, "*RST", 4, &retCnt)) < 0)
- return hp5313xa_status;
-
- if ((hp5313xa_status = hp5313xa_defaultInstrSetup (instrSession)) < 0)
- return hp5313xa_status;
-
-
- return hp5313xa_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 hp5313xa_selfTest (ViSession instrSession, ViPInt16 testResult,
- ViChar _VI_FAR testMessage[])
- {
- ViUInt32 retCnt = 0;
- ViStatus hp5313xa_status = VI_SUCCESS;
-
- if ((hp5313xa_status = viWrite (instrSession, "*TST?", 5, &retCnt)) < 0)
- return hp5313xa_status;
-
- if ((hp5313xa_status = viScanf (instrSession, "%hd,\"%[^\"]", testResult, testMessage)) < 0)
- return hp5313xa_status;
-
- return hp5313xa_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 hp5313xa_errorQuery (ViSession instrSession, ViPInt32 errCode,
- ViChar _VI_FAR errMessage[])
- {
- ViUInt32 retCnt = 0;
- ViStatus hp5313xa_status = VI_SUCCESS;
-
- if ((hp5313xa_status = viWrite (instrSession, ":SYST:ERR?", 10, &retCnt)) < 0)
- return hp5313xa_status;
-
- if ((hp5313xa_status = viScanf (instrSession, "%hd,\"%[^\"]", errCode, errMessage)) < 0)
- return hp5313xa_status;
-
-
- return hp5313xa_status;
- }
-
- /*===========================================================================*/
- /* Function: Error Message */
- /* Purpose: This function translates the error return value from the */
- /* instrument driver into a user-readable string. */
- /*===========================================================================*/
- ViStatus _VI_FUNC hp5313xa_errorMessage (ViSession instrSession, ViStatus errorCode,
- ViChar _VI_FAR errMessage[])
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViInt16 i;
- static hp5313xa_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"},
- {VI_ERROR_UPLOW_LIMIT, "ERROR: Upper Limit <= Lower Limit"},
-
- {VI_NULL, VI_NULL}
- };
-
- hp5313xa_status = viStatusDesc (instrSession, errorCode, errMessage);
- if (hp5313xa_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);
- }
-
- hp5313xa_status = VI_SUCCESS;
- return hp5313xa_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 hp5313xa_revisionQuery (ViSession instrSession,
- ViChar _VI_FAR driverRev[], ViChar _VI_FAR instrRev[])
- {
- ViUInt32 retCnt = 0;
- ViStatus hp5313xa_status = VI_SUCCESS;
-
- if ((hp5313xa_status = viWrite (instrSession, "*IDN?", 5, &retCnt)) < 0)
- return hp5313xa_status;
-
- if ((hp5313xa_status = viScanf (instrSession, "%*[^,],%*[^,],%*[^,],%[^\n]", instrRev)) < 0)
- return hp5313xa_status;
-
- strcpy (driverRev, hp5313xa_REVISION);
-
- return hp5313xa_status;
- }
-
- /*===========================================================================*/
- /* Function: Close */
- /* Purpose: This function closes the instrument. */
- /*===========================================================================*/
- ViStatus _VI_FUNC hp5313xa_close (ViSession instrSession)
- {
- hp5313xa_instrRange instrPtr;
- ViSession rmSession;
- ViStatus hp5313xa_status = VI_SUCCESS;
-
- if ((hp5313xa_status = viGetAttribute (instrSession, VI_ATTR_RM_SESSION, &rmSession)) < 0)
- return hp5313xa_status;
- if ((hp5313xa_status = viGetAttribute (instrSession, VI_ATTR_USER_DATA, &instrPtr)) < 0)
- return hp5313xa_status;
-
- free (instrPtr);
-
- hp5313xa_status = viClose (instrSession);
- viClose (rmSession);
-
- return hp5313xa_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 hp5313xa_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 hp5313xa_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 hp5313xa_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 hp5313xa_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 hp5313xa_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 hp5313xa_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 hp5313xa_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 hp5313xa_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 hp5313xa_init to */
- /* VI_NULL. */
- /*===========================================================================*/
- ViStatus hp5313xa_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 hp5313xa_readToFile (ViSession instrSession, ViString filename,
- ViUInt32 readBytes, ViPUInt32 retCount)
- {
- ViStatus hp5313xa_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)
- hp5313xa_status = viRead (instrSession, buffer, BUFFER_SIZE, &bytesReadInstr);
- else
- hp5313xa_status = viRead (instrSession, buffer, readBytes, &bytesReadInstr);
-
- bytesWrittenFile = fwrite (buffer, sizeof (ViByte), (size_t)bytesReadInstr, targetFile);
- *retCount += bytesWrittenFile;
- if (bytesWrittenFile < bytesReadInstr)
- hp5313xa_status = VI_ERROR_FILE_WRITE; /* not defined by VTL */
-
- if ((readBytes <= BUFFER_SIZE) || (hp5313xa_status <= 0) || (hp5313xa_status == VI_SUCCESS_TERM_CHAR))
- break;
-
- readBytes -= BUFFER_SIZE;
- }
-
- fclose (targetFile);
- return hp5313xa_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 hp5313xa_writeFromFile (ViSession instrSession, ViString filename,
- ViUInt32 writeBytes, ViPUInt32 retCount)
- {
- ViStatus hp5313xa_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);
- hp5313xa_status = viWrite (instrSession, buffer, BUFFER_SIZE, &bytesWritten);
- viSetAttribute (instrSession, VI_ATTR_SEND_END_EN, sendEnd);
- writeBytes -= BUFFER_SIZE;
- *retCount += bytesWritten;
- if (hp5313xa_status < 0)
- break;
- }
- else {
- hp5313xa_status = viWrite (instrSession, buffer, ((bytesRead < writeBytes) ? bytesRead : writeBytes), &bytesWritten);
- *retCount += bytesWritten;
- break;
- }
- }
-
- fclose (sourceFile);
- return hp5313xa_status;
- }
-
- /*****************************************************************************/
- /*----------- INSERT INSTRUMENT-DEPENDENT UTILITY ROUTINES HERE -------------*/
- /*****************************************************************************/
-
- /*=========================================================================*/
- /* Function: Get Instrument Error */
- /* Purpose: Check for an error. If a error occured within the hp5313xa then */
- /* that error will add an additional 740 to it to indicate an */
- /* instrument error. */
- /*=========================================================================*/
- ViStatus hp5313xa_get_error (ViSession instrSession)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViChar wrtBuf[256];
- ViUInt32 retCnt = 0;
- ViInt16 errCode = 0;
-
- if ((hp5313xa_status = viWrite (instrSession, ":SYST:ERR?", 10, &retCnt)) < 0)
- return hp5313xa_status;
-
- if ((hp5313xa_status = viScanf (instrSession, "%hd", &errCode)) < 0)
- return hp5313xa_status;
-
- if (errCode != 0)
- hp5313xa_status = VI_SYSTEM_ERROR;
-
- return hp5313xa_status;
- }
-
- /*=========================================================================*/
- /* Function: Serial Poll */
- /* Purpose: This function performs a serial poll on the instrument. */
- /* The status byte of the instrument is placed in the response */
- /* variable. */
- /*=========================================================================*/
- ViStatus hp5313xa_poll (ViSession instrSession, ViInt16 *response)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
-
- if ((hp5313xa_status = viReadSTB (instrSession, response)) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
- /*=========================================================================*/
- /* Function: Set Timeout */
- /* Purpose: This function changes or disables the timeout of the device. */
- /* Refer to the LabWindows Standard Libraries Reference Manual */
- /* for timeout codes. */
- /*=========================================================================*/
- ViStatus hp5313xa_set_timeout (ViSession instrSession, ViAttrState timeOutCode)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
-
- if (viSetAttribute (instrSession, VI_ATTR_TMO_VALUE, timeOutCode) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*===========================================================================*/
- /* Function: Default Instrument Setup */
- /* Purpose: This function sends a default setup to the instrument. This */
- /* function is called by the hp5313xa_reset operation and by the */
- /* hp5313xa_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 hp5313xa_defaultInstrSetup (ViSession instrSession)
- {
- ViStatus hp5313xa_status = VI_SUCCESS;
- ViUInt32 retCnt = 0;
-
- hp5313xa_instrRange instrPtr;
- instrPtr = malloc (sizeof (struct hp5313xa_statusDataRanges));
-
- instrPtr -> triggerMode = 0;
- instrPtr -> val2 = 0;
- instrPtr -> val3 = 0;
- strcpy (instrPtr -> instrDriverRevision, hp5313xa_REVISION);
-
- if (viSetAttribute (instrSession, VI_ATTR_USER_DATA, (ViUInt32)instrPtr) != 0)
- return hp5313xa_status;
-
- if (viSetAttribute (instrSession, VI_ATTR_TMO_VALUE, 13) != 0)
- return hp5313xa_status;
-
- return hp5313xa_status;
- }
-
- /*****************************************************************************/
- /*=== END INSTRUMENT DRIVER SOURCE CODE =====================================*/
- /*****************************************************************************/
-