⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rs.c.bak

📁 CVI例程
💻 BAK
📖 第 1 页 / 共 4 页
字号:
#include <ansi_c.h>
/***************************************************************************** 
 *  Copyright 1998 National Instruments Corporation.  All Rights Reserved.   * 
 *****************************************************************************/

    /*=CHANGE:===============================================================*
                INSTRUCTIONS TO THE INSTRUMENT DRIVER DEVELOPER
                         READ THESE INSTRUCTIONS FIRST!
     *=======================================================================*
                                                                             
        Congratulations!  You have successfully created all the files needed
        for your instrument driver - *.c,  *.h, *.fp, and *.sub.  These     
        files give you a framework to build your complete instrument driver 
        with the following features:                                    
            - IVI compliance                                             
            - VXIplug&play compliance                                    
            - Attribute model                                           
            - State caching                                             
            - Simulation                                                
            - Multithread safety                                         
                                                                        
        Before you can begin using this driver, you must perform the following 
        manual changes.                                 
                                                                        
        - If you are developing a driver for a register-based device, 
          remove the function panels for the RS_WriteInstrData 
          and RS_ReadInstrData functions.  These functions
          are for use with message-based instruments.                                       
                                                                            
        - Device-specific changes are marked with the comment "CHANGE".      
          Search for all occurrences of the word "CHANGE" and make the changes 
          for your specific instrument.  Delete the comments after you complete 
          the changes.
          
        - The IVI wizard might not properly align the code it generates.
          Review the resulting *.h and *.c files and reformat them as necessary.
          
        - Read the help text for the functions and attributes to understand
          the functionality you must implement in this driver.  The easiest
          way to view the help text is by using the RS.fp 
          function panels in "operate" mode.  You can view the help text for
          the attributes in any of the RS_GetAttribute 
          function panels.

        - Many of the functions contain extensive code examples within 
          comment blocks.  These code examples contain embedded comments.
          The only way to embed comments is by using double slashes (//).  
          Some C compilers do not accept double slashes.  If you are developing 
          this driver for general use, convert the double slashes to 
          traditional C comment markers.
        
        - Edit the Function Panel help.  Pay close attention to the default
          values and valid ranges for each parameter.  If you change the 
          default value for a control, you also need to change the default
          value in the help for the control.  Also, search for the comment 
          "CHANGE" in the help text, and make the appropriate changes.
          
        - Edit the help for all attributes with the attribute editor.  Pay close
          attention to the valid range information.  The Set/Get/Check attribute
          function panels automatically display valid range information for 
          attributes that have range tables of type IVI_VAL_DISCRETE or 
          IVI_VAL_COERCED.  You must edit/create the valid range information 
          in the description of an attribute if any of the following conditions 
          is true:
            * The attribute does not have a range table.
            * The attribute has a range table of type IVI_VAL_RANGED.
            * The attribute uses multiple static range tables or a dynamic
              range table.
            
          Also, look for "CHANGE" comments in the help text, and make the 
          appropriate changes.
           
        - Verify that all values that the header file defines are valid for 
          your instrument.  Delete the values that your instrument does not 
          use.
            
        - Delete these instructions and save the modified program.         

     *============================================================END=CHANGE=*/

/*****************************************************************************
 *  RS232 Instrument Driver                               
 *  LabWindows/CVI 5.0 Instrument Driver                                     
 *  Original Release: 01-8-14                                  
 *  By: ,                               
 *      PH.    Fax                               
 *                                                                           
 *  Modification History:                                                    
 *                                                                           
 *       01-8-14 - Instrument Driver Created.                  
 *                                                                           
 *****************************************************************************/

#include <string.h>
#include <stdio.h>  
#include <formatio.h>
#include "RS.h"

/*****************************************************************************
 *--------------------- Hidden Attribute Declarations -----------------------*
 *****************************************************************************/

#define RS_ATTR_OPC_TIMEOUT      (IVI_SPECIFIC_PRIVATE_ATTR_BASE + 1L)   /* ViInt32 */

/*****************************************************************************
 *---------------------------- Useful Macros --------------------------------*
 *****************************************************************************/

    /*- I/O buffer size -----------------------------------------------------*/
#define BUFFER_SIZE                             512L        

    /*- 488.2 Event Status Register (ESR) Bits ------------------------------*/
#define IEEE_488_2_QUERY_ERROR_BIT              0x04
#define IEEE_488_2_DEVICE_DEPENDENT_ERROR_BIT   0x08
#define IEEE_488_2_EXECUTION_ERROR_BIT          0x10
#define IEEE_488_2_COMMAND_ERROR_BIT            0x20

    /*- List of channels passed to the Ivi_BuildChannelTable function -------*/ 
#define CHANNEL_LIST                            "1"

static IviRangeTableEntry attrPressureRangeTableEntries[] =
	{
		{0.0, 50000.0, 0, "", 0},
		{IVI_RANGE_TABLE_LAST_ENTRY}
	};

static IviRangeTable attrPressureRangeTable =
	{
		IVI_VAL_RANGED,
        VI_TRUE,
        VI_TRUE,
        VI_NULL,
        attrPressureRangeTableEntries,
	};

static IviRangeTableEntry attrTempretureRangeTableEntries[] =
	{
		{-100.0, 150.0, 0, "", 0},
		{IVI_RANGE_TABLE_LAST_ENTRY}
	};

static IviRangeTable attrTempretureRangeTable =
	{
		IVI_VAL_RANGED,
        VI_TRUE,
        VI_TRUE,
        VI_NULL,
        attrTempretureRangeTableEntries,
	};

/*****************************************************************************
 *-------------- Utility Function Declarations (Non-Exported) ---------------*
 *****************************************************************************/
static ViStatus RS_InitAttributes (ViSession vi);
static ViStatus RS_DefaultInstrSetup (ViSession openInstrSession);
static ViStatus RS_CheckStatus (ViSession vi);
static ViStatus RS_WaitForOPC (ViSession vi, ViInt32 maxTime);

    /*- File I/O Utility Functions -*/
static ViStatus RS_ReadToFile (ViSession vi, ViConstString filename, 
                                     ViInt32 maxBytesToRead, ViInt32 fileAction, ViInt32 *totalBytesWritten);
static ViStatus RS_WriteFromFile (ViSession vi, ViConstString filename, 
                                        ViInt32 maxBytesToWrite, ViInt32 byteOffset, 
                                        ViInt32 *totalBytesWritten);

/*****************************************************************************
 *----------------- Callback Declarations (Non-Exported) --------------------*
 *****************************************************************************/

    /*- Global Session Callbacks --------------------------------------------*/
    
static ViStatus _VI_FUNC RS_CheckStatusCallback (ViSession vi, ViSession io);
static ViStatus _VI_FUNC RS_WaitForOPCCallback (ViSession vi, ViSession io);

    /*- Attribute callbacks -------------------------------------------------*/

static ViStatus _VI_FUNC RSAttrDriverRevision_ReadCallback (ViSession vi,
                                                                  ViSession io, 
                                                                  ViConstString channelName,
                                                                  ViAttr attributeId, 
                                                                  const ViConstString cacheValue);
static ViStatus _VI_FUNC RSAttrIdQueryResponse_ReadCallback (ViSession vi,
                                                                   ViSession io, 
                                                                   ViConstString channelName, 
                                                                   ViAttr attributeId, 
                                                                   const ViConstString cacheValue);


static ViStatus _VI_FUNC RSAttrPressure_ReadCallback (ViSession vi, ViSession io,
                                                      ViConstString channelName,
                                                      ViAttr attributeId,
                                                      ViReal64 *value);

static ViStatus _VI_FUNC RSAttrTempreture_ReadCallback (ViSession vi,
                                                        ViSession io,
                                                        ViConstString channelName,
                                                        ViAttr attributeId,
                                                        ViReal64 *value);



/*****************************************************************************
 *------------ User-Callable Functions (Exportable Functions) ---------------*
 *****************************************************************************/

/*****************************************************************************
 * Function: RS_init   
 * Purpose:  VXIplug&play required function.  Calls the   
 *           RS_InitWithOptions function.   
 *****************************************************************************/
ViStatus _VI_FUNC RS_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( RS_InitWithOptions (resourceName, IDQuery, resetDevice, 
                                        "", newVi));

Error:  
    return error;
}

/*****************************************************************************
 * Function: RS_InitWithOptions                                       
 * Purpose:  This function creates a new IVI session and calls the 
 *           IviInit function.                                     
 *****************************************************************************/
ViStatus _VI_FUNC RS_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 interchangeable driver */
    checkErr( Ivi_SpecificDriverNew ("RS", optionString, &vi));  
    
        /* init the driver */
    checkErr( RS_IviInit (resourceName, IDQuery, resetDevice, vi)); 
    *newVi = vi;
    
Error:
    if (error < VI_SUCCESS) 
        Ivi_Dispose (vi);
        
    return error;
}

/*****************************************************************************
 * Function: RS_IviInit                                                       
 * Purpose:  This function is called by RS_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 RS_IviInit (ViRsrc resourceName, ViBoolean IDQuery,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -