使用 Pilpxi

关于API提供的函数的详细信息,请参阅安装文件夹内的编程文件。


编译指南

要编译下面的任何示例,请确保在编译器中定义了包含pilpxi头文件的文件夹,通常是C:\ Program File(x86)\ Pickering Interfaces Ltd \ Pilpxi \ VC \。 库文件pilpxi.lib也必须添加到项目中。


打开板卡

这是使用pilpxi的最简单的程序,它打开PCI / PXI系统中的所有Pickering卡,为每个分配一个递增的数字“句柄”,从数值1开始。然后关闭所有板卡。

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

扩展代码以列出PCI / PXI系统中所有卡的标识。

#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;
}

更精简的方案是只打开所需的卡。 如果要通过不同的应用程序控制卡,必须要用这种方法,因为OpenCards会打开所有卡,从而阻止其他应用程序访问。 要确定系统中卡的地址,最简单的办法是运行位于安装文件夹中的Pickering诊断程序PipxDiag.exe,通常是在c:\ Pickering \ Diag,在报告中有所有Pickering卡的列表。

#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;
}

操作开关

一个简单的示例,打开指定的一张卡,然后关闭第一个开关。

#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;
}

稍复杂的一个示例,打开指定的一张卡,查询存在的子单元的数量和类型,然后操作每个开关,先关闭后打开。

#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;
}

使用模式操作开关

有时候能够在一次操作中设置整个子单元的开关是很有用的。 在下面的代码段中,假设数据大小为2个字节64位),实际上必须从卡中确定数据大小,或者从对卡认知来确定数据大小。

#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;
}

使用数字输入

有些卡包含数字输入子单元。

#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;
}

使用电阻卡

高精度电阻卡是通过请求电阻值来程控的。(较旧的电阻卡不使用此方法,而是当作开关来编程)

在大多数情况下,有两个特殊的电阻值用于将电阻设置为短路或开路。数值0.0为短路,用HUGE_VAL来设置开路, HUGE_VAL是双数据类型的最大值。

#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;
}
How did we do?
0 out of 0 people found this helpful.