Using Pilpxi

For full details of the functions provided by the API, please refer to one of the programming documents provided in the installation folder.


Compilation Guide

To compile any of the examples below, make sure that the folder containing the pilpxi header file is defined in the compiler, this is normally C:\Program File (x86)\Pickering Interfaces Ltd\Pilpxi\VC\. The library file pilpxi.lib must also be added to the project.


Opening Cards

This is the simplest possible program using pilpxi; it opens all Pickering cards in the PCI/PXI system, assigning each an ascending numeric 'handle', starting at a value of 1. It then closes all the cards.

#include "pilpxi.h"
 
int main()
{
    DWORD error, numCards;
    numCards = PIL_OpenCards();
 
    if (numCards > 0)
    {
        PIL_CloseCards();
    }
    return 0;
}

Extending the code to list the identity of all cards in the PCI/PXI system.

#include "pilpxi.h"
 
int main()
{
    DWORD error, numCards, card;
    char id[100];
 
    numCards = PIL_OpenCards();
 
    if (numCards > 0)
    {
        for(card = 1; card <= numCards; card++)
        {
            PIL_CardId(card, id);
            printf("Card %d identity string = %s\n", card, id);
        }
        PIL_CloseCards();
    }
    return 0;
}

A more elegant solution is to open only the required card. If cards are to be controlled from separate applications, this this approach is essential since OpenCards opens all cards and so prevents access by other applications. To ascertain the addresses of cards in the system, the easiest solution is to run the Pickering diagnostic program PipxDiag.exe located in the installation folder, normally c:\Pickering\Diag, within this report is a list of all Pickering cards.

#include "pilpxi.h"
 
int main()
{
    DWORD error, bus, slot, card;
    char id[100];
 
    /* Set bus and slot to the address of the required card */
    bus = 2;
    slot = 14;
 
    error = PIL_OpenSpecifiedCard(bus, slot, &card);
 
    if (error == NO_ERR)
    {
        PIL_CardId(card, id);
        printf("Card identity string = %s\n", id);
        PIL_CloseSpecifiedCard(card);
    }
    return 0;
}

Operating Switches

Simple example, opens a specified card and then closes the first switch.

#include "pilpxi.h"
 
int main()
{
    DWORD error, bus, slot, card, sub_unit, bit;
    BOOL state;
 
    /* Set bus and slot to the address of the required card */
    bus = 2;
    slot = 14;
    sub_unit = 1;
    bit = 1;
    state = TRUE;
 
 
    error = PIL_OpenSpecifiedCard(bus, slot, &card);
 
    if (error == NO_ERR)
    {
        PIL_OpBit(card, sub_unit, bit, state);
        PIL_CloseSpecifiedCard(card);
    }
    return 0;
}

More complex example, opens specified card, queries the number and type of sub-units present, then operates every switch, first closing then opening.

#include "pilpxi.h"
 
int main()
{
    DWORD error, bus, slot, card, sub_unit, bit, insubs, outsubs, sub, rows, cols, type;
 
    /* Set bus and slot to the address of the required card */
    bus = 2;
    slot = 14;
    sub_unit = 1;
    bit = 1;
 
 
    error = PIL_OpenSpecifiedCard(bus, slot, &card);
    if (error == NO_ERR)
    {
        PIL_EnumerateSubs(card, &insubs, &outsubs);
 
        for(sub = 1; sub <= outsubs; sub++)
        {
            PIL_SubInfo(card, sub, TRUE, &type, &rows, &cols);
            for(bit = 1; bit <= rows*cols; bit++)
            {
                PIL_OpBit(card, sub_unit, bit, TRUE);
                PIL_OpBit(card, sub_unit, bit, FALSE);
            }
        }
        PIL_CloseSpecifiedCard(card);
    }
 
    return 0;
}

Operating Switches using Patterns

Sometimes it is useful to be able to set the switches of an entire sub-unit in one operation. In the following code segment, a data size of 2 DWORDS (64 bits) has been assumed, in practice the data sze must be ascertained from the card, or from knowledge of the card.

#include "pilpxi.h"
 
int main()
{
    DWORD error, bus, slot, card, sub_unit;
    DWORD data[2];
 
    /* Set bus and slot to the address of the required card */
    bus = 2;
    slot = 14;
    sub_unit = 1;
 
    data[0] = 0xFFFFFFFF;
    data[1] = 0xFFFFFFFF;
 
    error = PIL_OpenSpecifiedCard(bus, slot, &card);
 
    if (error == NO_ERR)
    {
        PIL_WriteSub(card, sub_unit, data);
        PIL_CloseSpecifiedCard(card);
    }
    return 0;
}

Using Digital Inputs

Some cards contain digital input sub-units.

#include "pilpxi.h"
 
int main()
{
    DWORD error, bus, slot, card, sub_unit;
    DWORD data[1];
 
    /* Set bus and slot to the address of the required card */
    bus = 2;
    slot = 14;
    sub_unit = 1;
 
    error = PIL_OpenSpecifiedCard(bus, slot, &card);
 
    if (error == NO_ERR)
    {
        PIL_ReadSub(card, sub_unit, data);
        PIL_CloseSpecifiedCard(card);
    }
    return 0;
}

Using Resistor Cards

Precision resistor cards are programmed by requesting a value of resistance. (NB older resistor cards do not use this method and are programed as switches).

In most cases there are two special values of resistance used to set the resistor to short circuit or open circuit. Short circuit is set by programming a value of 0.0, open circuit by using HUGE_VAL, the maximum value of the double data type.

#include "pilpxi.h"
 
int main()
{
    DWORD error, bus, slot, card, sub_unit;
    double resistance;
 
    /* Set bus and slot to the address of the required card */
    bus = 2;
    slot = 14;
    sub_unit = 1;
 
    error = PIL_OpenSpecifiedCard(bus, slot, &card);
 
    if (error == NO_ERR)
    {
        /* set to 123.456 Ohms */
        resistance = 123.456;
        PIL_ResSetResistance(card, sub_unit, 0, resistance);
 
        /* set to short circuit */
        resistance = 0.0;
        PIL_ResSetResistance(card, sub_unit, 0, resistance);
 
        /* set to open circuit */
        resistance = HUGE_VAL;
        PIL_ResSetResistance(card, sub_unit, 0, resistance);
 
        PIL_CloseSpecifiedCard(card);
    }
    return 0;
}

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 videos,
to product literature and 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