📄 rs.c
字号:
{ return Ivi_WriteFromFile (vi, filename, maxBytesToWrite, byteOffset, totalBytesWritten); }/***************************************************************************** *------------------------ Global Session Callbacks -------------------------* *****************************************************************************//***************************************************************************** * Function: RS_CheckStatusCallback * Purpose: This function queries the instrument to determine if it has * encountered an error. If the instrument has encountered an * error, this function returns the IVI_ERROR_INSTRUMENT_SPECIFIC * error code. This function is called by the * RS_CheckStatus utility function. The * Ivi_SetAttribute and Ivi_GetAttribute functions invoke this * function when the optionFlags parameter includes the * IVI_VAL_DIRECT_USER_CALL flag. * * The user can disable calls to this function by setting the * IVI_ATTR_QUERY_INSTR_STATUS attribute to VI_FALSE. The driver can * disable the check status callback for a particular attribute by * setting the IVI_VAL_DONT_CHECK_STATUS flag. *****************************************************************************/static ViStatus _VI_FUNC RS_CheckStatusCallback (ViSession vi, ViSession io){ ViStatus error = VI_SUCCESS; /* Query instrument status */ /*=CHANGE:===============================================================* Change the *ESR? to the query command that requests the instrument to indicate whether it has encountered an error. The following example code is based on IEEE 488.2 Common System Commands. Example: ViInt16 esr = 0; viCheckErr( viWrite (io, "*ESR?", 5, VI_NULL)); viCheckErr( viScanf (io, "%hd", &esr)); if ((esr & IEEE_488_2_QUERY_ERROR_BIT) || (esr & IEEE_488_2_DEVICE_DEPENDENT_ERROR_BIT) || (esr & IEEE_488_2_EXECUTION_ERROR_BIT) || (esr & IEEE_488_2_COMMAND_ERROR_BIT)) { viCheckErr( IVI_ERROR_INSTR_SPECIFIC); } *============================================================END=CHANGE=*/ Error: return error;}/***************************************************************************** * Function: RS_WaitForOPCCallback * Purpose: This function waits until the instrument has finished processing * all pending operations. This function is called by the * RS_WaitForOPC utility function. The IVI engine invokes * this function in the following two cases: * - Before invoking the read callback for attributes for which the * IVI_VAL_WAIT_FOR_OPC_BEFORE_READS flag is set. * - After invoking the write callback for attributes for which the * IVI_VAL_WAIT_FOR_OPC_AFTER_WRITES flag is set. *****************************************************************************/static ViStatus _VI_FUNC RS_WaitForOPCCallback (ViSession vi, ViSession io){ ViStatus error = VI_SUCCESS; /*=CHANGE:===============================================================* Change this function to wait for operation complete for your specific instrument. This example function is based on the IEEE 488.2 Common System Commands. This example shows how to use the RS_ATTR_OPC_TIMEOUT hidden attribute to control the length of time this function waits. This function assumes that the instrument does not generate service requests for other reasons. This example performs the following operations: - Enables the service request event. - Sends a command that forces the instrument to generate a service request. - Waits for the service request. - Cleans up after the service request. ViInt32 opcTimeout; ViUInt16 statusByte; checkErr( Ivi_GetAttributeViInt32 (vi, VI_NULL, RS_ATTR_OPC_TIMEOUT, 0, &opcTimeout)); viCheckErr( viEnableEvent (io, VI_EVENT_SERVICE_REQ, VI_QUEUE, VI_NULL)); viCheckErr( viPrintf (io, "*OPC")); // wait for SRQ viCheckErr( viWaitOnEvent (io, VI_EVENT_SERVICE_REQ, opcTimeout, VI_NULL, VI_NULL)); viCheckErr( viDisableEvent (io, VI_EVENT_SERVICE_REQ, VI_QUEUE)); // clean up after SRQ viCheckErr( viBufWrite (io, "*CLS", 4, VI_NULL)); viCheckErr( viReadSTB (io, &statusByte)); Error: viDiscardEvents (io, VI_EVENT_SERVICE_REQ, VI_QUEUE); *============================================================END=CHANGE=*/ return error;}/***************************************************************************** *----------------- Attribute Range Tables and Callbacks --------------------* *****************************************************************************//*- RS_ATTR_ID_QUERY_RESPONSE -*/static ViStatus _VI_FUNC RSAttrIdQueryResponse_ReadCallback (ViSession vi, ViSession io, ViConstString channelName, ViAttr attributeId, const ViConstString cacheValue){ ViStatus error = VI_SUCCESS; ViChar rdBuffer[BUFFER_SIZE]; ViUInt32 retCnt; viCheckErr( viPrintf (io, "*IDN?\r")); viCheckErr( viRead (io, rdBuffer, BUFFER_SIZE-1, &retCnt)); rdBuffer[retCnt] = 0; checkErr( Ivi_SetValInStringCallback (vi, attributeId, rdBuffer)); Error: return error;} /*- RS_ATTR_DRIVER_REVISION -*/static ViStatus _VI_FUNC RSAttrDriverRevision_ReadCallback (ViSession vi, ViSession io, ViConstString channelName, ViAttr attributeId, const ViConstString cacheValue){ ViStatus error = VI_SUCCESS; ViChar driverRevision[256]; sprintf (driverRevision, "Driver: RS %.2f, Compiler: %s %3.2f, " "Components: IVIEngine %.2f, VISA-Spec %.2f", RS_MAJOR_VERSION + RS_MINOR_VERSION/1000.0, IVI_COMPILER_NAME, IVI_COMPILER_VER_NUM, IVI_ENGINE_MAJOR_VERSION + IVI_ENGINE_MINOR_VERSION/1000.0, Ivi_ConvertVISAVer(VI_SPEC_VERSION)); checkErr( Ivi_SetValInStringCallback (vi, attributeId, driverRevision)); Error: return error;}static ViStatus _VI_FUNC RSAttrPressure_ReadCallback (ViSession vi, ViSession io, ViConstString channelName, ViAttr attributeId, ViReal64 *value){ ViStatus error = VI_SUCCESS; ViChar buf[20]={""}; viCheckErr( viPrintf (io, "*PRESSURE?" ) ); viCheckErr( viScanf (io,"%s", buf) ); *value=atof(buf); Error: return error;}static ViStatus _VI_FUNC RSAttrTemperature_ReadCallback (ViSession vi, ViSession io, ViConstString channelName, ViAttr attributeId, ViReal64 *value){ ViStatus error = VI_SUCCESS; ViChar buf[20]={""}; viCheckErr( viPrintf (io, "*TEMPRETURE?" ) ); viCheckErr( viScanf (io,"%s", buf) ); *value=atof(buf);Error: return error;}/***************************************************************************** * Function: RS_InitAttributes * Purpose: This function adds attributes to the IVI session, initializes * instrument attributes, and sets attribute invalidation * dependencies. *****************************************************************************/static ViStatus RS_InitAttributes (ViSession vi){ ViStatus error = VI_SUCCESS; /*=CHANGE:=============================================================* NOTE TO THE DEVELOPER: You can add additional parameters to the prototype of this function. This is useful when you want to pass information from the initialization functions. The Attribute Editor in LabWindows/CVI requires that the name of this function be RS_InitAttributes. *==========================================================END=CHANGE=*/ /*- Initialize instrument attributes --------------------------------*/ checkErr( Ivi_SetAttributeViInt32 (vi, VI_NULL, RS_ATTR_DRIVER_MAJOR_VERSION, 0, RS_MAJOR_VERSION)); checkErr( Ivi_SetAttributeViInt32 (vi, VI_NULL, RS_ATTR_DRIVER_MINOR_VERSION, 0, RS_MINOR_VERSION)); checkErr( Ivi_SetAttrReadCallbackViString (vi, RS_ATTR_DRIVER_REVISION, RSAttrDriverRevision_ReadCallback)); checkErr( Ivi_SetAttributeViAddr (vi, VI_NULL, IVI_ATTR_OPC_CALLBACK, 0, RS_WaitForOPCCallback)); checkErr( Ivi_SetAttributeViAddr (vi, VI_NULL, IVI_ATTR_CHECK_STATUS_CALLBACK, 0, RS_CheckStatusCallback)); checkErr( Ivi_SetAttributeViBoolean (vi, VI_NULL, IVI_ATTR_SUPPORTS_WR_BUF_OPER_MODE, 0, VI_FALSE)); /*- Add instrument-specific attributes ------------------------------*/ checkErr( Ivi_AddAttributeViString (vi, RS_ATTR_ID_QUERY_RESPONSE, "RS_ATTR_ID_QUERY_RESPONSE", "RS232", IVI_VAL_NOT_USER_WRITABLE, RSAttrIdQueryResponse_ReadCallback, VI_NULL)); checkErr( Ivi_AddAttributeViInt32 (vi, RS_ATTR_OPC_TIMEOUT, "RS_ATTR_OPC_TIMEOUT", 5000, IVI_VAL_HIDDEN | IVI_VAL_DONT_CHECK_STATUS, VI_NULL, VI_NULL, VI_NULL)); checkErr (Ivi_AddAttributeViReal64 (vi, RS_ATTR_TEMPERATURE, "RS_ATTR_TEMPERATURE", 0, 0, RSAttrTemperature_ReadCallback, VI_NULL, &attrTemperatureRangeTable, 0)); checkErr (Ivi_AddAttributeViReal64 (vi, RS_ATTR_PRESSURE, "RS_ATTR_PRESSURE", 0, 0, RSAttrPressure_ReadCallback, VI_NULL, &attrPressureRangeTable, 0)); /*- Setup attribute invalidations -----------------------------------*/ /*=CHANGE:===============================================================* Set attribute dependencies by calling the additional Ivi_AddAttributeInvalidation functions here. Remove the dependencies that do not apply to your instrument by deleting the calls to Ivi_AddAttributeInvalidation. When you initially add an attribute, it applies to all channels. If you want it to apply to only a subset, call the Ivi_RestrictAttrToChannels function. *============================================================END=CHANGE=*/Error: return error;}/***************************************************************************** *------------------- End Instrument Driver Source Code ---------------------* *****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -