1、GPIB编程资料上面的网页有些 GPIB编程的资料不过 NI的列子是最简单明了的:* Refer to the language interface documentation for details on* which header and .obj files to include in your project.*/#include #include “decl-32.h“#include void GpibError(char *msg); /* Error function declaration */int Device = 0; /* Device unit descriptor
2、 */int BoardIndex = 0; /* Interface Index (GPIB0=0,GPIB1=1,etc.) */void main() int PrimaryAddress = 2; /* Primary address of the device */int SecondaryAddress = 0; /* Secondary address of the device */char Buffer101; /* Read buffer */* Initialization - Done only once at the beginning of your applica
3、tion.*/Device = ibdev( /* Create a unit descriptor handle */BoardIndex, /* Board Index (GPIB0 = 0, GPIB1 = 1, .) */PrimaryAddress, /* Device primary address */SecondaryAddress, /* Device secondary address */T10s, /* Timeout setting (T10s = 10 seconds) */1, /* Assert EOI line at end of write */0); /*
4、 EOS termination mode */if (ibsta ibclr(Device); /* Clear the device */if (ibsta /* Main Application Body - Write the majority of your GPIB code here.*/ibwrt(Device, “*IDN?“, 5); /* Send the identification query command */if (ibsta ibrd(Device, Buffer, 100); /* Read up to 100 bytes from the device *
5、/if (ibsta Bufferibcntl = 0; /* Null terminate the ASCII string */printf(“%sn“, Buffer); /* Print the device identification */* Uninitialization - Done only once at the end of your application.*/ibonl(Device, 0); /* Take the device offline */if (ibsta ibonl(BoardIndex, 0); /* Take the interface offl
6、ine */if (ibsta /* Function GPIBERROR* This function will 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*
7、 along with the mnemonic meaning of the decimal 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(char *msg) printf (“%sn“, msg);printf (“ibsta = p
8、rintf (“iberr = %d“, iberr);if (iberr = EDVR) printf (“ EDVR n“);if (iberr = ECIC) printf (“ ECIC n“);if (iberr = ENOL) printf (“ ENOL n“);if (iberr = EADR) printf (“ EADR n“);if (iberr = EARG) printf (“ EARG n“);if (iberr = ESAC) printf (“ ESAC n“);if (iberr = EABO) printf (“ EABO n“);if (iberr = E
9、NEB) printf (“ ENEB n“);if (iberr = EOIP) printf (“ EOIP n“);if (iberr = ECAP) printf (“ ECAP n“);if (iberr = EFSO) printf (“ EFSO n“);if (iberr = EBUS) printf (“ EBUS n“);if (iberr = ESTB) printf (“ ESTB n“);if (iberr = ESRQ) printf (“ ESRQ n“);if (iberr = ETAB) printf (“ ETAB n“);printf (“ibcntl = %ldn“, ibcntl);printf (“n“);/* Call ibonl to take the device and interface offline */ibonl (Device,0);ibonl (BoardIndex,0);exit(1);