📄 fl45.c
字号:
{ ViStatus error = VI_SUCCESS; ViStatus overRange = VI_SUCCESS; checkErr( Ivi_LockSession(vi, VI_NULL)); if (reading == VI_NULL) viCheckParm( IVI_ERROR_INVALID_PARAMETER, 3, "Null address for Reading"); checkErr( FL45_Initiate (vi)); checkWarn (overRange = FL45_Fetch (vi, maxTime, reading)); checkErr( FL45_CheckStatus (vi)); Error: Ivi_UnlockSession(vi, VI_NULL); if (error < VI_SUCCESS) return error; else return overRange;} /***************************************************************************** * Function: FL45_Initiate * Purpose: Initates a measurement. *****************************************************************************/ViStatus _VI_FUNC FL45_Initiate (ViSession vi){ ViStatus error = VI_SUCCESS; checkErr( Ivi_LockSession (vi, VI_NULL)); if (!Ivi_Simulating(vi)) /* call only when locked */ { ViSession io = Ivi_IOSession(vi); /* call only when locked */ ViInt32 triggersource; /* The Fluke 45 continually initiates measurements. After the Fluke 45 takes a measurement, it immediately waits for a trigger to take another measurement. This function makes sure that the Fluke 45 actually takes the measurement that the FL45_Measure, FL45_Read, and FL45_Fetch functions return after this function executes. If the trigger source is set to FL45_VAL_EXTERNAL or FL45_VAL_GPIB_GET this function clears any measurements that might have been taken prior to the execution of this function. */ checkErr( Ivi_GetAttributeViInt32 (vi, VI_NULL, FL45_ATTR_TRIGGER_SOURCE, 0, &triggersource)); switch (triggersource) { case FL45_VAL_EXTERNAL: case FL45_VAL_GPIB_GET: case FL45_VAL_SW_TRIG_FUNC: checkErr( Ivi_SetAttributeViInt32 (vi, VI_NULL, FL45_ATTR_TRIGGER_SOURCE, 0, FL45_VAL_IMMEDIATE)); checkErr( Ivi_SetAttributeViInt32 (vi, VI_NULL, FL45_ATTR_TRIGGER_SOURCE, 0, triggersource)); break; } } /* Do not invoke the FL45_CheckStatus function here. It is invoked by the high-level driver functions when this function is used interally. After the user calls this function, the end- user can check for errors by calling the FL45_error_query function. */ Error: Ivi_UnlockSession (vi, VI_NULL); return error;}/***************************************************************************** * Function: FL45_Abort * Purpose: Aborts a measurement. *****************************************************************************/ViStatus _VI_FUNC FL45_Abort (ViSession vi){ ViStatus error = VI_SUCCESS; checkErr( Ivi_LockSession(vi, VI_NULL)); if (!Ivi_Simulating(vi)) /* call only when locked */ { ViSession io = Ivi_IOSession(vi); /* call only when locked */ checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE)); viCheckErr( viClear (io)); } /* Do not invoke the FL45_CheckStatus function here. After the user calls this function, the user can check for errors by calling the FL45_error_query function. */Error: Ivi_UnlockSession(vi, VI_NULL); return error;}/***************************************************************************** * Function: FL45_SendSWTrigger * Purpose: Sends a command to trigger the instrument. *****************************************************************************/ViStatus _VI_FUNC FL45_SendSWTrigger (ViSession vi){ ViStatus error = VI_SUCCESS; checkErr( Ivi_LockSession(vi, VI_NULL)); if (!Ivi_Simulating(vi)) /* call only when locked */ { ViSession io = Ivi_IOSession(vi); /* call only when locked */ checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE)); viCheckErr( viWrite (io, "*TRG;", 5, VI_NULL)); } /* Do not invoke the FL45_CheckStatus function here. After the user calls this function, the user can check for errors by calling the FL45_error_query function. */ Error: Ivi_UnlockSession(vi, VI_NULL); return error;}/***************************************************************************** * Function: FL45_IsOverRange * Purpose: This function takes a measurement value that you obtain from one * of the Measure, Read, or Fetch functions and determines if the * value is a valid measurement value or a value indicating an * over-range condition occurred. *****************************************************************************/ViStatus _VI_FUNC FL45_IsOverRange (ViSession vi, ViReal64 measurementValue, ViBoolean *isOverRange){ ViStatus error = VI_SUCCESS; ViInt32 type; checkErr( Ivi_LockSession(vi, VI_NULL)); if (isOverRange == VI_NULL) viCheckParm( IVI_ERROR_INVALID_PARAMETER, 3, "Null address for Is Over-Range."); viCheckErr( Ivi_GetViReal64Type (measurementValue, &type)); if (type == IVI_VAL_TYPE_NAN) *isOverRange = VI_TRUE; else *isOverRange = VI_FALSE;Error: Ivi_UnlockSession(vi, VI_NULL); return error;}/**************************************************************************** * Function: FL45_Hold * Purpose: Asserts a 'hold' if hold mode is enabled. ****************************************************************************/ViStatus _VI_FUNC FL45_Hold (ViSession vi) { ViStatus error = VI_SUCCESS; ViBoolean holdMode; checkErr( Ivi_LockSession (vi, VI_NULL)); checkErr( Ivi_GetAttributeViBoolean (vi, VI_NULL, FL45_ATTR_HOLD_ENABLE, 0, &holdMode)); if (!holdMode) viCheckErrElab( IVI_ERROR_INVALID_CONFIGURATION, "Enable the hold " "modifier before calling this function."); if (!Ivi_Simulating (vi)) { ViSession io = Ivi_IOSession (vi); checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE)); viCheckErr( viPrintf (io, "HOLD;")); } checkErr( FL45_CheckStatus(vi)); Error: Ivi_UnlockSession (vi, VI_NULL); return error; }/***************************************************************************** * Function: FL45_Fetch * Purpose: This function returns the measured value from a previously * initiated measurement. This function does not trigger the * instrument. * * After this function executes, the value in *readingRef * is an actual reading or a value indicating that an over-range * condition occurred. If an over-range condition occurs, the * function sets *readingRef to IVI_VAL_NAN * and returns FL45_WARN_OVER_RANGE. *****************************************************************************/ViStatus _VI_FUNC FL45_Fetch (ViSession vi, ViInt32 maxTime, ViReal64 *readingRef){ ViStatus error = VI_SUCCESS; ViReal64 reading; ViBoolean overRange = VI_FALSE; ViSession io; ViUInt32 oldTimeout; ViBoolean needToRestoreTimeout = VI_FALSE; checkErr( Ivi_LockSession (vi, VI_NULL)); if (readingRef == VI_NULL) viCheckParm( IVI_ERROR_INVALID_PARAMETER, 3, "Null address for Reading"); if (!Ivi_Simulating(vi)) /* call only when locked */ { io = Ivi_IOSession(vi); /* call only when locked */ checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE)); viCheckErr( viGetAttribute (io, VI_ATTR_TMO_VALUE, &oldTimeout)); viCheckErr( viSetAttribute (io, VI_ATTR_TMO_VALUE, maxTime)); needToRestoreTimeout = VI_TRUE; viCheckErr( viPrintf (io, "VAL1?;")); viCheckErr( viScanf (io, "%lf", &reading)); /* Test for over range */ if ((reading >= 1000000000.0) || (reading <= -1000000000.0)) { *readingRef = IVI_VAL_NAN; /* Over ranged, set to NaN. */ overRange = VI_TRUE; } else { *readingRef = reading; } } else if (Ivi_UseSpecificSimulation (vi)) { /* Simulate measurement data */ ViReal64 range; checkErr( Ivi_GetAttributeViReal64 (vi, VI_NULL, FL45_ATTR_RANGE, 0, &range)); if (range <= 0.0) /* If auto-ranging, use the max value. */ checkErr( Ivi_GetAttrMinMaxViReal64 (vi, VI_NULL, FL45_ATTR_RANGE, VI_NULL, &range, VI_NULL, VI_NULL)); *readingRef = range * ((ViReal64)rand() / (ViReal64)RAND_MAX); } /* Do not invoke FL45_CheckStatus here. FL45_Read invokes FL45_CheckStatus after it calls this function. After the user calls this function, the user can check for errors by calling FL45_error_query. */ Error: if (needToRestoreTimeout) { /* Restore the original timeout */ viSetAttribute (io, VI_ATTR_TMO_VALUE, oldT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -