对GPIB卡编程使其可以监听两个不同的主地址



硬件: GPIB>>Plug-in Controllers>>NB-GPIB-P/TNT, GPIB>>Plug-in Controllers>>SB-GPIB/TNT, GPIB>>Plug-in Controllers>>AT-GPIB/TNT (PnP), GPIB>>Plug-in Controllers>>AT-GPIB/TNT+, GPIB>>Plug-in Controllers>>NEC-GPIB/TNT, GPIB>>Plug-in Controllers>>GPIB-SPRC-B/TNT, GPIB>>Plug-in Controllers>>AT-GPIB/TNT, GPIB>>Plug-in Controllers>>NB-GPIB/TNT, GPIB>>Plug-in Controllers>>NEC-GPIB/TNT (PnP)

问题: 我知道GPIB控制器一般都有一个主地址,用于监听和发送,但是我想同时监听两个地址。我能使我的GPIB卡同时监听两个主地址吗?

解答: 下面的例程对于可以让任何一款使用TNT4882ASIC的National Instruments GPIB卡都是可用的。目录页面显示了每一张卡所使用的芯片。

这一例程将修改一些在TNT4882芯片上的寄存器使它能对两个主地址都响应。接下来的循环显示了哪一个地址被设置为发送


// Add appropriate include files. These are appropriate for LabWindows/CVI
#include <utility.h>
#include <gpib.h>
#include <stdio.h>

// Set Major and Minor Primary Addresses
#define PA1 0x01
#define PA2 0x04

void main ()
{
int board;
char buffer[100];
char byte;
int address;

board = ibfind ("GPIB0");
ibrsc (board, 0);

// Determine Address of GPIB board
// ibdiag will read some information from the table in memory
// bits 27 and 26 combine to make up the base address of I/O
// mapped boards (ie, not PCI boards which are memory mapped)
ibdiag(board, buffer, 100);
address = (((buffer[27] << 8) & 0xFF00) | (buffer[26] & 0x00FF));

outp (address + 0x8, 0x31); // ADR: Set Dual Addressing
outp (address + 0xC, PA1); // ARD1: Primary PA2
outp (address + 0xC, PA2 | 0x80); // ADR2: Secondary PA3

while (1) // Loop Forever
{
ibwait(board, 0); // Read Status

if ((ibsta & 0x04) && !(ibsta & 0x10)) // LACS + !ATN
{
byte = inp (address + 0x08); // Read Major/Minor #

if (byte & 0x1) // If bit 0 is set, it is the Minor #
printf("Primary Address %d is a Listener\n", PA2);
else
printf("Primary Address %d is a Listener\n", PA1);
} // if LACS + !ATN

if ((ibsta & 0x08) && !(ibsta & 0x10)) // TACS + !ATN
{
byte = inp (address + 0x08); // Read Major/Minor #

if (byte & 0x1)
printf("Primary Address %d is a Talker\n", PA2);
else
printf("Primary Address %d is a Talker\n", PA1);
} // if TACS + !ATN
} // while
} // main


源代码同时也贴在了附件中

相关链接: Products and Services: GPIB Plug-In Controllers
Products and Services: GPIB External Controllers

附件:


twoaddr.c - twoaddr.c


报告日期: 03/25/1998
最近更新: 10/10/2013
文档编号: 17O7K8QA