1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include "Decl-32.h"
#include <iostream.h>
void gpib_error(int errnum,char *errmsg);
const int BUF_SIZE = 1024;
const int NUM_DEVICES = 31;
int main(int argc, char* argv[])
{
char buffer[BUF_SIZE];
int i, num_listeners;
unsigned short address;
Addr4882_t instruments[NUM_DEVICES],result[NUM_DEVICES],meas[NUM_DEVICES];
SendIFC(0);
if(ibsta & ERR)
{
gpib_error(1,"could not send IFC");
}
for(i=0; i< NUM_DEVICES - 1; i++)
{
instruments[i] = i+1;
}
instruments[NUM_DEVICES - 1] = NOADDR;
cout<<"finding all listerners on the bus ..."<<endl;
FindLstn(0,instruments,result, NUM_DEVICES);
num_listeners = ibcnt;
result[num_listeners] = NOADDR;
cout<<"found"<<num_listeners<<"device on the bus"<<endl;
SendList(0,result,"*IDN?",5L,NLend);
if(ibsta & ERR)
{
gpib_error(3,"could not send *IDN");
}
for(i=0; i<num_listeners; i++)
{
Receive(0,result[i],buffer,BUF_SIZE,STOPend);
if(ibsta & ERR)
{
gpib_error(4,"could not received from device");
}
address = GetPAD(result[i]);
cout<<"Device#"<<address<<"has ID string : "<<buffer<<endl;
}
ibonl(0,0);
return 0;
}
void gpib_error(int errnum,char *errmsg)
{
cout<<"Error#"<<errnum<<": "<<errmsg<<endl;
ibonl(0,0);
exit(1);
} |