1、GPIB编程资料 上面的网页有些GPIB编程的资料不过NI的列子是最简单明了的: ***************************************************************************** * Refer to the language interface documentation for details on * which header and .obj files to include in your project. *******************************************************
2、/
#include
3、dex (GPIB0=0,GPIB1=1,etc.) */ void main() { int PrimaryAddress = 2; /* Primary address of the device */ int SecondaryAddress = 0; /* Secondary address of the device */ char Buffer[101]; /* Read buffer */ /*******
4、 * Initialization - Done only once at the beginning of your application. *****************************************************************************/ Device = ibdev( /* Create a unit descriptor handle
5、 */ BoardIndex, /* Board Index (GPIB0 = 0, GPIB1 = 1, ...) */ PrimaryAddress, /* Device primary address */ SecondaryAddress, /* Device secondary address */ T10s, /* Timeout settin
6、g (T10s = 10 seconds) */ 1, /* Assert EOI line at end of write */ 0); /* EOS termination mode */ if (ibsta & ERR) { /* Check for GPIB Error */ GpibError("ibdev Erro
7、r"); } ibclr(Device); /* Clear the device */ if (ibsta & ERR) { GpibError("ibclr Error"); } /***************************************************************************** * Main Application Body - Write the majority of your GPIB code h
8、ere. *****************************************************************************/ ibwrt(Device, "*IDN?", 5); /* Send the identification query command */ if (ibsta & ERR) { GpibError("ibwrt Error"); } ibrd(Device, Buffer, 100); /* Read up to 100 bytes from the devi
9、ce */ if (ibsta & ERR) { GpibError("ibrd Error"); } Buffer[ibcntl] = '\0'; /* Null terminate the ASCII string */ printf("%s\n", Buffer); /* Print the device identification */ /*************************************************************
10、 * Uninitialization - Done only once at the end of your application. *****************************************************************************/ ibonl(Device, 0); /* Take the device offline */ if (ibsta & ERR) { GpibError("ibonl Error"
11、); } ibonl(BoardIndex, 0); /* Take the interface offline */ if (ibsta & ERR) { GpibError("ibonl Error"); } } /***************************************************************************** * Function GPIBERROR * This function w
12、ill notify you that a NI-488 function failed by * printing an error message. The status variable IBSTA will also be * printed in hexadecimal along with the mnemonic meaning of the bit * position. The status variable IBERR will be printed in decimal * along with the mnemonic meaning of the decim
13、al value. The status * variable IBCNTL will be printed in decimal. * * The NI-488 function IBONL is called to disable the hardware and * software. * * The EXIT function will terminate this program. *****************************************************************************/ void GpibError
14、char *msg) { printf ("%s\n", msg); printf ("ibsta = &H%x <", ibsta); if (ibsta & ERR ) printf (" ERR"); if (ibsta & TIMO) printf (" TIMO"); if (ibsta & END ) printf (" END"); if (ibsta & SRQI) printf (" SRQI"); if (ibsta & RQS ) printf (" RQS"); if (ibs
15、ta & CMPL) printf (" CMPL"); if (ibsta & LOK ) printf (" LOK"); if (ibsta & REM ) printf (" REM"); if (ibsta & CIC ) printf (" CIC"); if (ibsta & ATN ) printf (" ATN"); if (ibsta & TACS) printf (" TACS"); if (ibsta & LACS) printf (" LACS"); if (ibsta & DTAS)
16、 printf (" DTAS");
if (ibsta & DCAS) printf (" DCAS");
printf (" >\n");
printf ("iberr = %d", iberr);
if (iberr == EDVR) printf (" EDVR
17、"); if (iberr == EADR) printf (" EADR
\n"); if (iberr == EARG) printf (" EARG18、o GPIB board>\n");
if (iberr == EOIP) printf (" EOIP
19、f (" ESTB \n");
printf ("ibcntl = %ld\n", ibcntl);
printf ("\n");
/* Call ibonl to take the device and interface offline */
ibonl (Device,0);
ibonl (BoardIndex,0);
exit(1);
}