📄 rs.c
字号:
ViBoolean reset, ViSession vi){ ViStatus error = VI_SUCCESS; ViSession io = VI_NULL; checkErr( Ivi_BuildChannelTable (vi, CHANNEL_LIST, VI_FALSE, VI_NULL)); /* Add attributes */ checkErr( RS_InitAttributes (vi)); if (!Ivi_Simulating(vi)) { 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 | VI_WRITE_BUF, 4000)); 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( RS_reset (vi)); else /*- Send Default Instrument Setup ---------------------------------*/ checkErr( RS_DefaultInstrSetup (vi)); /*- Identification Query ------------------------------------------------*/ if (IDQuery) { ViChar rdBuffer[BUFFER_SIZE]; #define VALID_RESPONSE_STRING_START "RS232" checkErr( Ivi_GetAttributeViString (vi, VI_NULL, RS_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( RS_CheckStatus (vi)); if (reset && error == VI_SUCCESS ) viCheckWarn( VI_WARN_NSUP_RESET);Error: if (error < VI_SUCCESS) { if (!Ivi_Simulating (vi) && io) viClose (io); } return error;}/***************************************************************************** * Function: RS_close * Purpose: This function closes the instrument. * * Note: This function must unlock the session before calling * Ivi_Dispose. *****************************************************************************/ViStatus _VI_FUNC RS_close (ViSession vi){ ViStatus error = VI_SUCCESS; checkErr( Ivi_LockSession (vi, VI_NULL)); checkErr( RS_IviClose (vi));Error: Ivi_UnlockSession (vi, VI_NULL); Ivi_Dispose (vi); return error;}/***************************************************************************** * Function: RS_IviClose * Purpose: This function performs all of the drivers clean-up operations * except for closing the IVI session. This function is called by * RS_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 RS_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: RS_reset * Purpose: This function resets the instrument. *****************************************************************************/ViStatus _VI_FUNC RS_reset (ViSession vi){ ViStatus error = VI_SUCCESS; checkErr( Ivi_LockSession (vi, VI_NULL)); checkErr( RS_DefaultInstrSetup (vi)); if ( error == VI_SUCCESS ) viCheckWarn( VI_WARN_NSUP_RESET);Error: Ivi_UnlockSession (vi, VI_NULL); return error;}/***************************************************************************** * Function: RS_self_test * Purpose: This function executes the instrument self-test and returns the * result. *****************************************************************************/ViStatus _VI_FUNC RS_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"); viCheckWarn( VI_WARN_NSUP_SELF_TEST);Error: Ivi_UnlockSession(vi, VI_NULL); return error;}/***************************************************************************** * Function: RS_error_query * Purpose: This function queries the instrument error queue and returns * the result. *****************************************************************************/ViStatus _VI_FUNC RS_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"); viCheckWarn( VI_WARN_NSUP_ERROR_QUERY);Error: Ivi_UnlockSession(vi, VI_NULL); return error;}/***************************************************************************** * Function: RS_error_message * Purpose: This function translates the error codes returned by this * instrument driver into user-readable strings. * * Note: The caller can pass VI_NULL for the vi parameter. This * is useful if one of the init functions fail. *****************************************************************************/ViStatus _VI_FUNC RS_error_message (ViSession vi, ViStatus errorCode, ViChar errorMessage[256]){ ViStatus error = VI_SUCCESS; static IviStringValueTable errorTable = { /*=CHANGE:================================================================* Insert instrument driver specific error codes here. Example: {RS_ERROR_TOO_MANY_SAMPLES, "Sample Count cannot exceed 512."}, *=============================================================END=CHANGE=*/ {VI_NULL, VI_NULL} }; if (vi) Ivi_LockSession(vi, VI_NULL); /* all VISA and IVI error codes are handled as well as codes in the table */ if (errorMessage == VI_NULL) viCheckParm( IVI_ERROR_INVALID_PARAMETER, 3, "Null address for Error Message"); checkErr( Ivi_GetSpecificDriverStatusDesc(vi, errorCode, errorMessage, errorTable));Error: if (vi) Ivi_UnlockSession(vi, VI_NULL); return error;}/***************************************************************************** * Function: RS_revision_query * Purpose: This function returns the driver and instrument revisions. *****************************************************************************/ViStatus _VI_FUNC RS_revision_query (ViSession vi, ViChar driverRev[], ViChar instrRev[]){ ViChar rdBuffer[BUFFER_SIZE]; ViStatus error = VI_SUCCESS; checkErr( Ivi_LockSession (vi, VI_NULL)); if (driverRev == VI_NULL) viCheckParm( IVI_ERROR_INVALID_PARAMETER, 2, "Null address for Driver Revision"); if (instrRev == VI_NULL) viCheckParm( IVI_ERROR_INVALID_PARAMETER, 3, "Null address for Instrument Revision"); checkErr( Ivi_GetAttributeViString (vi, VI_NULL, IVI_ATTR_DRIVER_REVISION, 0, -1, driverRev)); viCheckWarn( VI_WARN_NSUP_REV_QUERY); checkErr( RS_CheckStatus (vi));Error: Ivi_UnlockSession(vi, VI_NULL); return error;}/***************************************************************************** * Function: RS_GetAttribute<type> Functions * Purpose: These functions enable the instrument driver user to get * attribute values directly. There are typesafe versions for * ViInt32, ViReal64, ViString, ViBoolean, and ViSession attributes. *****************************************************************************/ViStatus _VI_FUNC RS_GetAttributeViInt32 (ViSession vi, ViConstString channelName, ViAttr attributeId, ViInt32 *value){ return Ivi_GetAttributeViInt32 (vi, channelName, attributeId, IVI_VAL_DIRECT_USER_CALL, value);} ViStatus _VI_FUNC RS_GetAttributeViReal64 (ViSession vi, ViConstString channelName, ViAttr attributeId, ViReal64 *value){ return Ivi_GetAttributeViReal64 (vi, channelName, attributeId, IVI_VAL_DIRECT_USER_CALL, value);} ViStatus _VI_FUNC RS_GetAttributeViString (ViSession vi, ViConstString channelName, ViAttr attributeId, ViInt32 bufSize, ViChar value[]) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -