Writing Interchangeable Code Using the IVI Driver

    While it is possible to embed a specific driver into your code, the full power of the IVI driver concept is only fully realized if the code is written in a way to make the code interchangeable from one card to another. Here's how to do it using National Instruments software and Pickering switch cards.

    First, make suitable definitions of the card in MAX. Define a Driver Session referring to the specific card to be controlled and make a Logical Name referring to the Driver Session.

    This code shows 3 different ways in which the card can be initialized:

        ViStatus err;
        ViSession vi;
        ViInt32 num_chans;
        ViInt32 i;
        char name[100];
        char msg[256];
     
     
     
     
        // a) pi40iv_InitWithOptions         NO INTERCHANGABILITY
     
    // This offers NO interchangability since:
    // a) The specific driver is coded
    // b) The specific card model is called
     
        err = pi40iv_InitWithOptions(    "PXI5::15::INSTR",
                        VI_FALSE,
                        VI_FALSE,
                        "Simulate=0,RangeCheck=1,QueryInstrStatus=1,Cache=1,DriverSetup=Model:41-182-003;",
                        &vi);
        if  (err != VI_SUCCESS)
        {
            pi40iv_error_message(0, err, msg);
            printf("%s\n", msg);
        }
        else
        {
            pi40iv_close(vi);
        }
     
     
     
     
     
        // b) pi40iv_init                  INTERCHANGEABLE WITH OTHER PICKERING CARDS
     
     
    // In this case the card model is dealt with in the IVI configuration store
    // Which means the card could be re-defined in the store
    // However, the Pickering driver is still explicitly called
     
     
        err = pi40iv_init("atten_ln", 0, 0, &vi);
        if  (err != VI_SUCCESS)
        {
            pi40iv_error_message(0, err, msg);
            printf("%s\n", msg);
        }
        else
        {
            pi40iv_close(vi);
        }
     
     
     
     
     
        // c) IviSwtch_init                      FULLY INTERCHANGEABLE BETWEEN MANUFACTURERS
     
     
    // In this case the generic class driver is used
    // The driver session in the IVI configuration store specifies the driver to use
    // This is fully interchangable - a change to the card model and/or the driver is achieved
    // by editing the configuration store and requires no code changes
     
     
        err = IviSwtch_init("atten_ln", 0, 0, &vi);
        if  (err != VI_SUCCESS)
        {
            IviSwtch_error_message(0, err, msg);
            printf("%s\n", msg);
        }
        else
        {
            IviSwtch_close(vi);
        }
     
     


    In the 2nd case the code does not explicitly refer to the Pickering card, this is handled in MAX. The resource string is a a Logical Name, if a different card is required, it is sufficient to modify the settings in MAX to point to a different Driver Session. In this case any suitable Pickering switch card could be interchanged with the original simply by modifying the IVI configuration store in MAX.


    In the 3rd case the Pickering driver is not referred to, instead the generic IviSwtch class driver is used. In this scenario it becomes possible to interchange switch cards from different manufacturers, again defined in the IVI configuration store.


    Of course, it is essential that the alternate card offer all the channel names used by the original, so normally it is not possible to substitute a card of smaller size, however any card of similar capability may now be substituted for the original by a simple change to the settings in MAX. The code remains unchanged.


    The main MAX entry in the above examples is this:

    Image of MAX entry into the measurement and automation explorer


    Where cards with different default channel names are interchanged, the channels may be given Virtual Names in the IVI configuration store, which may also be edited in MAX.

    Need help?



    Support knowledgebase

    Have questions or need some help? While we enjoy talking to you, you can find technical information for our entire product range here.

    Technical know-how 


    Long-term support

    Because we manufacture our products in-house, we are able to provide you with guaranteed long-term support and low obsolescence.

    Our support


    Resource center

    From success stories and product literature to newsletters, find the information you need about our switching and simulation solutions.

    Get the resources you need


    Worldwide presence

    We supply and support our products across the globe, with seven offices in the Americas, Europe and Asia as well as additional representation. 

    Find a local office or agent near you