📄 hp33120a.c
字号:
IviRangeTablePtr *rangeTablePtr);static ViStatus _VI_FUNC hp33120aAttrOutputMode_CheckCallback (ViSession vi, ViConstString channelName, ViAttr attributeId, ViInt32 value);/***************************************************************************** *------------ User-Callable Functions (Exportable Functions) ---------------* *****************************************************************************//***************************************************************************** * Function: hp33120a_init * Purpose: VXIplug&play required function. Calls the * hp33120a_InitWithOptions function. *****************************************************************************/ViStatus _VI_FUNC hp33120a_init (ViRsrc resourceName, ViBoolean IDQuery, ViBoolean resetDevice, ViSession *newVi){ ViStatus error = VI_SUCCESS; if (newVi == VI_NULL) { Ivi_SetErrorInfo (VI_NULL, VI_FALSE, IVI_ERROR_INVALID_PARAMETER, VI_ERROR_PARAMETER4, "Null address for Instrument Handle"); checkErr( IVI_ERROR_INVALID_PARAMETER); } checkErr( hp33120a_InitWithOptions (resourceName, IDQuery, resetDevice, "", newVi));Error: return error;}/***************************************************************************** * Function: hp33120a_InitWithOptions * Purpose: This function creates a new IVI session and calls the * IviInit function. *****************************************************************************/ViStatus _VI_FUNC hp33120a_InitWithOptions (ViRsrc resourceName, ViBoolean IDQuery, ViBoolean resetDevice, ViString optionString, ViSession *newVi){ ViStatus error = VI_SUCCESS; ViSession vi = VI_NULL; if (newVi == VI_NULL) { Ivi_SetErrorInfo (VI_NULL, VI_FALSE, IVI_ERROR_INVALID_PARAMETER, VI_ERROR_PARAMETER5, "Null address for Instrument Handle"); checkErr( IVI_ERROR_INVALID_PARAMETER); } *newVi = VI_NULL; /* create a new interchangable driver */ checkErr( Ivi_SpecificDriverNew ("hp33120a", optionString, &vi)); /* init the driver */ checkErr( hp33120a_IviInit (resourceName, IDQuery, resetDevice, vi)); *newVi = vi; Error: if (error < VI_SUCCESS) Ivi_Dispose (vi); return error;}/***************************************************************************** * Function: hp33120a_IviInit * Purpose: This function is called by hp33120a_InitWithOptions * or by an IVI class driver. This function initializes the I/O * interface, optionally resets the device, optionally performs an * ID query, and sends a default setup to the instrument. *****************************************************************************/ViStatus _VI_FUNC hp33120a_IviInit (ViRsrc resourceName, ViBoolean IDQuery, ViBoolean reset, ViSession vi){ ViStatus error = VI_SUCCESS; ViSession io = VI_NULL; checkErr( Ivi_BuildChannelTable (vi, HP33120A_CHANNEL_LIST, VI_FALSE, VI_NULL)); /* Add attributes */ checkErr( hp33120a_InitAttributes (vi)); if (!Ivi_Simulating(vi)) /* called only when session is locked */ { ViSession rmSession = VI_NULL; /* Open instrument session */ checkErr( Ivi_GetAttributeViSession (vi, VI_NULL, IVI_ATTR_VISA_RM_SESSION, 0, &rmSession)); viCheckErr( viOpen (rmSession, resourceName, VI_NULL, VI_NULL, &io)); /* io session owned by driver now */ checkErr( Ivi_SetAttributeViSession (vi, VI_NULL, IVI_ATTR_IO_SESSION, 0, io)); /* Configure VISA Formatted I/O */ viCheckErr( viSetAttribute (io, VI_ATTR_TMO_VALUE, 5000 )); viCheckErr( viSetBuf (io, VI_READ_BUF, 4000)); viCheckErr( viSetBuf (io, VI_WRITE_BUF, 32100)); viCheckErr( viSetAttribute (io, VI_ATTR_WR_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS)); viCheckErr( viSetAttribute (io, VI_ATTR_RD_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS)); } /*- Reset instrument ----------------------------------------------------*/ if (reset) checkErr( hp33120a_reset (vi)); else /*- Send Default Instrument Setup ---------------------------------*/ checkErr( hp33120a_DefaultInstrSetup (vi)); /* Identification Query */ if (IDQuery) { ViChar rdBuffer[BUFFER_SIZE]; #define VALID_RESPONSE_STRING_START "HEWLETT-PACKARD,33120A" checkErr( Ivi_GetAttributeViString (vi, VI_NULL, HP33120A_ATTR_ID_QUERY_RESPONSE, 0, BUFFER_SIZE, rdBuffer)); if (strncmp (rdBuffer, VALID_RESPONSE_STRING_START, strlen(VALID_RESPONSE_STRING_START)) != 0) { viCheckErr( VI_ERROR_FAIL_ID_QUERY); } } checkErr( hp33120a_CheckStatus (vi));Error: if (error < VI_SUCCESS) { if (!Ivi_Simulating (vi) && io) viClose (io); } return error;}/***************************************************************************** * Function: hp33120a_close * Purpose: This function closes the instrument. * * Note: This function must unlock the session before calling * Ivi_Dispose. *****************************************************************************/ViStatus _VI_FUNC hp33120a_close (ViSession vi){ ViStatus error = VI_SUCCESS; checkErr( Ivi_LockSession (vi, VI_NULL)); checkErr( hp33120a_IviClose (vi));Error: Ivi_UnlockSession (vi, VI_NULL); Ivi_Dispose (vi); return error;}/***************************************************************************** * Function: hp33120a_IviClose * Purpose: This function performs all of the drivers clean-up operations * except for closing the IVI session. This function is called by * hp33120a_close or by an IVI class driver. * * Note: This function must close the I/O session and set * IVI_ATTR_IO_SESSION to 0. *****************************************************************************/ViStatus _VI_FUNC hp33120a_IviClose (ViSession vi){ ViStatus error = VI_SUCCESS; ViSession io = VI_NULL; /* Do not lock here. The caller manages the lock. */ checkErr( Ivi_GetAttributeViSession (vi, VI_NULL, IVI_ATTR_IO_SESSION, 0, &io));Error: Ivi_SetAttributeViSession (vi, VI_NULL, IVI_ATTR_IO_SESSION, 0, VI_NULL); if(io) { viClose (io); } return error; }/***************************************************************************** * Function: hp33120a_reset * Purpose: This function resets the instrument. *****************************************************************************/ViStatus _VI_FUNC hp33120a_reset (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( viPrintf (io, "*RST")); } checkErr( hp33120a_DefaultInstrSetup (vi)); checkErr( hp33120a_CheckStatus (vi));Error: Ivi_UnlockSession (vi, VI_NULL); return error;}/***************************************************************************** * Function: hp33120a_self_test * Purpose: This function executes the instrument self-test and returns the * result. *****************************************************************************/ViStatus _VI_FUNC hp33120a_self_test (ViSession vi, ViInt16 *testResult, ViChar testMessage[]){ ViStatus error = VI_SUCCESS; checkErr( Ivi_LockSession (vi, VI_NULL)); if (testResult == VI_NULL) viCheckParm( IVI_ERROR_INVALID_PARAMETER, 2, "Null address for Test Result"); if (testMessage == VI_NULL) viCheckParm( IVI_ERROR_INVALID_PARAMETER, 3, "Null address for Test Message"); if (!Ivi_Simulating(vi)) /* call only when locked */ { ViSession io = Ivi_IOSession(vi); /* call only when locked */ checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE)); viCheckErr( viPrintf (io, "*TST?")); viCheckErr( viScanf (io, "%hd,\"%256[^\"]", testResult, testMessage)); } else if (Ivi_UseSpecificSimulation(vi)) /* call only when locked */ { /* Simulate Self Test */ *testResult = 0; strcpy (testMessage, "No error."); } checkErr( hp33120a_CheckStatus (vi));Error: Ivi_UnlockSession(vi, VI_NULL); return error;}/***************************************************************************** * Function: hp33120a_error_query * Purpose: This function queries the instrument error queue and returns * the result. *****************************************************************************/ViStatus _VI_FUNC hp33120a_error_query (ViSession vi, ViInt32 *errCode, ViChar errMessage[]){ ViStatus error = VI_SUCCESS; checkErr( Ivi_LockSession (vi, VI_NULL)); if (errCode == VI_NULL) viCheckParm( IVI_ERROR_INVALID_PARAMETER, 2, "Null address for Error Code"); if (errMessage == VI_NULL) viCheckParm( IVI_ERROR_INVALID_PARAMETER, 3, "Null address for Error Message");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -